Posts

Post not yet marked as solved
1 Replies
111 Views
I want to integrate an apple pay account on the website, but on the point where I am validating merchant that return "false" responses . I already followed the documentation and tried many times but still did not resolve it. Please help me to resolve this issue. so that i can integrate apple pay for heartland. here i mentioned my block of code where i am verifying merchant, please help to fix this. server side code: (PHP): $merchantSession = fetchAppleMerchantSession($validationURL); echo json_encode($merchantSession); function fetchAppleMerchantSession($validationUrl){ $cert_url = base_path('cert/merchant.pem'); $cert_key = base_path('cert/merchant.key'); $data = [ 'merchantIdentifier' => 'domain.com', 'domainName' => 'domain.com', 'displayName' => 'Disp Name', 'initiative' => 'web', 'initiativeContext' => 'domain.com' ]; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $validationUrl); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data)); curl_setopt($ch, CURLOPT_CERTINFO, true); curl_setopt($ch, CURLOPT_VERBOSE, true); curl_setopt($ch, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1_2); curl_setopt($ch, CURLOPT_SSLCERT, $cert_url); curl_setopt($ch, CURLOPT_SSLKEY, $cert_key); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json")); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $res = curl_exec($ch); curl_close($ch); $result = json_encode($res); return ['data' => $result, 'status' => false]; } client side code (JS): // Create Apple Pay session within the user gesture handler const session = new ApplePaySession(6, paymentRequest); // Handle merchant validation session.onvalidatemerchant = (event) => { console.log("event", {event, session}); const validationURL = event.validationURL; fetch('gp_applepay_validate.php', { // Replace with your server-side validation endpoint method: 'POST', headers: { 'Content-Type': 'application/json', 'Access-Control-Allow-Headers': "*" }, body: JSON.stringify({ validationURL }), }) .then((response) => { console.log("response.json()", response); return response.json(); }) .then((data) => { console.log("datappp", data); if (data.status) { event.completeMerchantValidation(data.data); } else { console.error('Merchant validation failed:', data.data); session.abort(); alert('Payment failed: ' + data.data); // Improve error message } }) .catch((error) => { console.error('Error during merchant validation:', error); session.abort(); alert('An error occurred during payment. Please try again later.'); // Generic error message for user }); };
Posted Last updated
.