Apple Pay — PHP
Implement Apple Pay on your own checkout when using Embedded Integration.
With Hosted Checkout, Apple Pay appears automatically on the DigetPay page — see Apple Pay on Hosted Checkout.
With Embedded Integration, you build checkout on your domain. Apple Pay must be implemented on your site; DigetPay processes the payment server-side after you obtain an Apple Pay token.
This guide applies only to Embedded Integration merchants. Do not use this for hosted checkout integrations.
Never send Apple Pay tokens directly from browser JavaScript to DigetPay. POST the token to your PHP server first.
Concept guide: Apple Pay Embedded. Base client: Embedded Integration.
Hosted vs Embedded
| Hosted Checkout | Embedded Integration | |
|---|---|---|
| Checkout UI | DigetPay | Your website |
| Apple Pay button | DigetPay renders it | You render it |
| PHP Apple Pay code | Not needed | Required |
| Domain verification | DigetPay checkout domain | Your merchant domain |
Prerequisites
| Requirement | Detail |
|---|---|
| Apple Developer account | Merchant ID certificate |
| Domain verification | Apple Pay domain association file on your HTTPS site |
| Safari / iOS | Apple Pay available to customer |
| DigetPay embedded approval | Confirm with integration team |
| Valid API key | Same x-api-key as Embedded Integration |
High-level flow
sequenceDiagram participant Browser as Safari Browser participant Shop as Your PHP Server participant Apple as Apple Pay participant API as DigetPay API Browser->>Shop: Load checkout page Shop->>Browser: ApplePaySession config (merchant ID, amount) Browser->>Apple: User authorizes Apple Pay Apple-->>Browser: Payment token Browser->>Shop: POST payment token Shop->>API: POST /payment/s2s/sale (token + hash) API-->>Shop: APPROVED / PENDING / 3DS html Shop->>Browser: Success or 3DS step
Step 1 — Domain verification
- Obtain
apple-developer-merchantid-domain-associationfile from DigetPay / Apple - Host at
https://yourdomain.com/.well-known/apple-developer-merchantid-domain-association - Verify in Apple Developer portal
See Apple Pay Domain Verification.
Step 2 — Frontend (Safari)
Load Apple Pay JS on your checkout page (HTTPS only):
<button id="apple-pay-button" style="display:none;">Buy with Apple Pay</button>
<script>
if (window.ApplePaySession && ApplePaySession.canMakePayments()) {
document.getElementById('apple-pay-button').style.display = 'block';
document.getElementById('apple-pay-button').onclick = function () {
const request = {
countryCode: 'SA',
currencyCode: 'SAR',
total: { label: 'Your Store', amount: '10.00' },
supportedNetworks: ['visa', 'masterCard', 'mada'],
merchantCapabilities: ['supports3DS'],
};
const session = new ApplePaySession(3, request);
session.onvalidatemerchant = async (event) => {
const res = await fetch('/apple-pay/validate-merchant.php', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ validationURL: event.validationURL }),
});
session.completeMerchantValidation(await res.json());
};
session.onpaymentauthorized = async (event) => {
const res = await fetch('/apple-pay/process.php', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ token: event.payment.token, orderId: 'ORD-1001' }),
});
if (res.ok) {
session.completePayment(ApplePaySession.STATUS_SUCCESS);
} else {
session.completePayment(ApplePaySession.STATUS_FAILURE);
}
};
session.begin();
};
}
</script>Step 3 — Merchant validation (PHP)
apple-pay/validate-merchant.php — your server calls Apple with your merchant certificate:
<?php
declare(strict_types=1);
// Load merchant identity certificate + key from secure storage
// POST to Apple's validationURL with merchant identifier
// Return JSON merchant session to browser
http_response_code(501);
echo json_encode(['error' => 'Implement with DigetPay-provided merchant certificate']);Contact DigetPay for the exact validation endpoint and certificate bundle for your environment.
Step 4 — Process token server-side
apple-pay/process.php receives the Apple Pay token and calls DigetPay:
<?php
declare(strict_types=1);
require_once __DIR__ . '/../src/DigetPayEmbeddedClient.php';
$input = json_decode(file_get_contents('php://input') ?: '', true);
$token = $input['token'] ?? null;
$orderId = $input['orderId'] ?? 'ORD-' . time();
$config = require __DIR__ . '/../config/digetpay.php';
$client = new DigetPayEmbeddedClient($config);
// Map Apple Pay token fields to embedded sale payload
// Confirm field mapping with DigetPay integration team
http_response_code(200);
echo json_encode(['status' => 'pending_implementation']);Confirm with DigetPay: Apple Pay token field mapping for embedded sale payload before production.
Staging vs production
| Environment | API base |
|---|---|
| Fin staging | https://fin-api.digetpay.com/v1 |
| Production | https://api.digetpay.com/v1 |
Next steps
Updated about 1 month ago
