-
Notifications
You must be signed in to change notification settings - Fork 89
/
validateApplePayMerchant.php
50 lines (43 loc) · 2.21 KB
/
validateApplePayMerchant.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php
// Validation URL is passed in the request
// Sandbox is https://apple-pay-gateway-cert.apple.com/paymentservices/startSession
//$validationUrl=$_POST['validationUrl'];
$validationUrl="https://apple-pay-gateway-cert.apple.com/paymentservices/startSession";
$pemPwd = getenv("PEM_PWD");
$domainName = getenv("DOMAIN_NAME");
$merchantId = getenv("MERCHANT_ID");
// JSON Payload
$validationPayload = '{"merchantIdentifier": "merchant.authorize.net.test.dev15","domainName": "accept-sample.azurewebsites.net","displayName":"ApplePayDemoTestDev15"}';
try{ //setting the curl parameters.
$ch = curl_init();
if (FALSE === $ch)
throw new Exception('failed to initialize');
curl_setopt($ch, CURLOPT_URL, $validationUrl);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $validationPayload);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 300);
// The following two curl SSL options are set to "false" for ease of development/debug purposes only.
// Any code used in production should either remove these lines or set them to the appropriate
// values to properly use secure connections for PCI-DSS compliance.
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); //for production, set value to true or 1
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); //for production, set value to 2
curl_setopt($ch, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1_2);
curl_setopt($ch, CURLOPT_SSLCERT, './certs/apple-pay-test-cert.pem');
curl_setopt($ch, CURLOPT_SSLCERTPASSWD, $pemPwd);
curl_setopt($ch, CURLOPT_DNS_USE_GLOBAL_CACHE, false );
$content = curl_exec($ch);
if (FALSE === $content)
{
print_r(curl_error($ch));
throw new Exception(curl_error($ch), curl_errno($ch));
}
curl_close($ch);
print_r($content);
// $content is the Apple Response, it should be a merchant session object
// but may need to do some manipulation here
}catch(Exception $e) {
trigger_error(sprintf('Curl failed with error #%d: %s', $e->getCode(), $e->getMessage()), E_USER_ERROR);
}
?>