Post

Replies

Boosts

Views

Activity

Reply to How do I send a request using the Apple Pay merchant certificate
I have finally solved this problem. My code is as follows for friends who need it. <?php require __DIR__ . '/../vendor/autoload.php'; use GuzzleHttp\Client; use GuzzleHttp\Exception\RequestException; use GuzzleHttp\RequestOptions; // HTTP Client $client = new Client([ 'base_uri' => 'https://cn-apple-pay-gateway.apple.com/', // or https://apple-pay-gateway.apple.com/ 'timeout' => 30.0, 'http_errors' => false, 'transport' => [], ]); // key and cert option $options = [ RequestOptions::HEADERS => [ 'Content-Type' => 'application/json', ], RequestOptions::JSON => [ 'merchantIdentifier' => 'merchant.hiseer.web', 'displayName' => 'displayName', 'initiative' => 'web', 'initiativeContext' => 'shop.wowseer.com', ], 'ssl_key' => './cert/merchantKey.key', // key file 'cert' => './cert/merchantCert.pem', // cert file ]; try { // post request $response = $client->post('paymentservices/paymentSession', $options); // check status code if ($response->getStatusCode() === 200) { // echo response body echo $response->getBody()->getContents(); } else { echo "Failed to send request: " . $response->getStatusCode() . "\n"; echo $response->getBody()->getContents(); } } catch (RequestException $e) { // error handling echo "Request error: " . $e->getMessage() . "\n"; if ($e->hasResponse()) { echo "Response status code: " . $e->getResponse()->getStatusCode() . "\n"; echo $e->getResponse()->getBody()->getContents(); } }
Topic: Safari & Web SubTopic: General Tags:
Apr ’25