ApplePay
| 功能 | 说明 |
|---|---|
| 支付LOGO-使用规范 | |
| 集成方案 |
|
| 推荐使用国家 | 全球 |
| 是否支持虚拟行业 | ✅ |
| 是否支持订阅服务 | ✅ 视行业而定 |
| 支持的SaaS | 支持所有已对接的SaaS清单 |
| 支持的开源建站 |
|
集成方式
嵌入式
要使用嵌入式集成方式时:
- 商户需要为其注册的每个域名在以下路径托管域名验证文件,并确保此路径文件可以正常访问:
⬇️ 点击下载域名验证文件
https://[DOMAIN_NAME]/.well-known/apple-developer-merchantid-domain-association
注意
如果您有多个二级或其他域名,都需要添加以上验证文件,例如:
https://example.com/.well-known/apple-developer-merchantid-domain-association
https://test.example.com/.well-known/apple-developer-merchantid-domain-association
···
- 发起域名校验:
- Request
- Response
cURL -X POST 'https://mds.oceanpayment.com/appleregistermerchant'
-H 'Authorization: MVc9Lt1CDY7RBRUvh8iVmvvPbYF3uvWkymUDz'
-d '{
"website": ["example.com,test.example.com"]
}'
{
"statusMessage": "Success",
"statusCode": 200
}
- 错误处理
| 响应码 | 说明 |
|---|---|
| 200 | OK
|
| 400 | Bad Request
|
| 401 | Unauthorized
|
| 417 | Expectation Failed
|
| 500 | Internal Server Error
|
- 完成域名校验后,结账页面将在可能的情况下显示ApplePay作为付款选项。
注意
嵌入式集成ApplePay仅适用于支持它的Apple设备(例如Safari网页浏览器、iOS设备),且支付按钮仅在iOS 17及以上版本才会显示。
- 使用嵌入式集成方案完成对接。
服务器对服务器
要使用此集成模式,需要先成为ApplePay官方开发者。
- ApplePay开发者账号注册与配置
- 访问https://developer.apple.com
- 选择Apple Developer Program;
- 支付对接必须使用 企业账号,个人账号无法创建Merchant ID。
- 创建Merchant ID
- 登录Apple Developer → Certificates, Identifiers & Profiles;
- 点击左侧菜单Identifiers → Merchant IDs → (+),创建Merchant ID。
- 生成Merchant Identity Certificate
- 在 Mac上使用 Keychain或OpenSSL生成 CSR(Certificate Signing Request);
- 回到 Apple Developer → Certificates → 添加证书;
- 上传CSR,Apple返回.cer文件;
- 下载并安装到本地,导出.p12文件;
- .p12用于支付网关或中间服务器与Apple进行签名加密通信。
- 配置Merchant Domain白名单
- 登录Apple Developer → Merchant IDs → Domain Verification;
- 添加商户域名(如 payments.oceanpayment.com);
- 按提示下载验证文件 apple-developer-merchantid-domain-association;
- 上传到网站根目录,如:https://payments.oceanpayment.com/.well-known/apple-developer-merchantid-domain-association
- 点击Verify完成验证。
- 获取ApplePay Payment Token,查看ApplePay完整示例,将Token通过
pay_accountNumber参数传值Oceanpayment,调用服务器对服务器。
const paymentRequest = {
countryCode: 'US',
currencyCode: 'USD',
total: {
label: 'OceanPayment Checkout',
amount: '10.00',
},
supportedNetworks: ['visa', 'masterCard', 'amex'],
merchantCapabilities: ['supports3DS'],
merchantIdentifier: 'merchant.oceanpayment.test',
};
session.onpaymentauthorized = function (event) {
const payment = event.payment;
console.log(JSON.stringify(payment));
console.log(JSON.stringify(payment.token));
processPayment(payment.token).then(function (response) {
console.log("response from datatrans received");
console.log(response);
if (response.match(/status=.error./)) {
console.log("an error occured!");
console.log(response);
return session.abort();
}
session.completePayment(ApplePaySession.STATUS_SUCCESS);
window.location.href = "/success.html";
});
};
function processPayment(paymentToken) {
let paymentMethod = paymentToken.paymentMethod;
let cardType = paymentMethod.network;
let environment = document.getElementById('environment').value;
let account = payParams[environment].account;
let terminal = payParams[environment].terminal;
let orderNo = new Date().getTime();
let orderCurrency = document.getElementById('#order_currency').value;
let orderAmount = document.getElementById('#order_amount').value;
document.getElementById('form').action = payParams[environment].url;
document.getElementById('account').value = account;
document.getElementById('terminal').value = terminal;
document.getElementById('pay_accountNumber').value = paymentToken.paymentData;
document.getElementById('card_type').value = cardType;
document.getElementById('order_number').value = orderNo;
document.getElementById('order_amount').value = orderAmount;
document.getElementById('methods').value = 'ApplePay';
let billingId = document.getElementById('billing_id').value;
let billingFirstName = document.getElementById('billing_firstName').value;
let billingLastName = document.getElementById('billing_lastName').value;
let billingEmail = document.getElementById('billing_email').value;
let signString = account + terminal + orderNo + orderCurrency + orderAmount
+ billingId + billingFirstName + billingLastName + billingEmail + payParams[environment].secureCode;
document.getElementById('signValue').value = sha256_digest(signString);
document.getElementById('form').submit();
}