amzn / amazon-pay-api-sdk-php
Amazon Pay API SDK (PHP)
Requires
- php: >=5.6.1
- ext-curl: *
- phpseclib/phpseclib: ~3.0
Requires (Dev)
- phpunit/phpunit: ^4
README
Amazon Pay 集成
请注意,Amazon Pay API SDK 仅可用于调用 pay-api.amazon.com|eu|jp 端点的 API。
如果您需要使用 mws.amazonservices.com|jp 或 mws-eu.amazonservices.com 端点进行 Amazon Pay API 调用,则需要使用原始的 Amazon Pay SDK (PHP)。
要求
- PHP 5.6.1 或更高版本,但强烈建议只使用最新的 PHP 版本,并经常更新,以确保应用最新的安全修复
- Curl 7.18 或更高
- phpseclib 3.0
SDK 安装
使用 composer 安装 SDK 的最新版本及其依赖项
composer require amzn/amazon-pay-api-sdk-php
使用以下测试脚本来验证安装
<?php include 'vendor/autoload.php'; echo "SDK_VERSION=" . Amazon\Pay\API\Client::SDK_VERSION . "\n"; ?>
公共和私有密钥
来自先前 MWS 集成的 MWS 访问密钥、MWS 秘密密钥和 MWS 授权令牌不能与该 SDK 一起使用。
您需要生成自己的公私钥对,以便使用该 SDK 进行 API 调用。
在 Windows 10 中,可以使用 ssh-keygen 命令完成此操作
ssh-keygen -t rsa -b 2048 -f private.pem
ssh-keygen -f private.pem -e -m PKCS8 > public.pub
在 Linux 或 macOS 中,可以使用 openssl 命令完成此操作
openssl genrsa -out private.pem 2048
openssl rsa -in private.pem -pubout > public.pub
上面的第一个命令生成一个私有密钥,第二个命令使用私有密钥生成一个公共密钥。
要将密钥与您的帐户关联,请按照以下说明获取您的公共密钥 ID。
命名空间
此包的命名空间为 Amazon\Pay\API,以确保与使用 AmazonPay 命名空间的原始 Amazon Pay MWS SDK 无冲突。
配置数组
$amazonpay_config = array( 'public_key_id' => 'ABC123DEF456XYZ', // RSA Public Key ID (this is not the Merchant or Seller ID) 'private_key' => 'keys/private.pem', // Path to RSA Private Key (or a string representation) 'sandbox' => true, // true (Sandbox) or false (Production) boolean 'region' => 'us', // Must be one of: 'us', 'eu', 'jp' 'algorithm' => 'AMZN-PAY-RSASSA-PSS-V2' //Amazon Signing Algorithm, Optional: uses AMZN-PAY-RSASSA-PSS if not specified 'integrator_id' => 'AXXXXXXXXXXXXX', // (optional) Solution Provider Platform Id in Amz UID Format 'integrator_version' => '1.2.3', // (optional) Solution Provider Plugin Version in Semantic Versioning Format 'platform_version' => '0.0.4' // (optional) Solution Provider Platform Version in Semantic Versioning Format );
如果您已在 Seller Central 中创建了特定环境的密钥(例如,公共密钥以 LIVE 或 SANDBOX 开头),则请使用这些 PublicKeyId 和 PrivateKey。在这种情况下,无需向 ApiConfiguration 传递 Sandbox 参数。
$amazonpay_config = array( 'public_key_id' => 'MY_PUBLIC_KEY_ID', // LIVE-XXXXX or SANDBOX-XXXXX 'private_key' => 'keys/private.pem', // Path to RSA Private Key (or a string representation) 'region' => 'us', // Must be one of: 'us', 'eu', 'jp' 'algorithm' => 'AMZN-PAY-RSASSA-PSS-V2' //Amazon Signing Algorithm, Optional: uses AMZN-PAY-RSASSA-PSS if not specified );
如果您想启用代理支持,可以在 $amazonpay_config 中按以下方式设置:
$amazonpay_config = array( 'public_key_id' => 'ABC123DEF456XYZ', // RSA Public Key ID (this is not the Merchant or Seller ID) 'private_key' => 'keys/private.pem', // Path to RSA Private Key (or a string representation) 'sandbox' => true, // true (Sandbox) or false (Production) boolean 'region' => 'us', // Must be one of: 'us', 'eu', 'jp' 'algorithm' => 'AMZN-PAY-RSASSA-PSS-V2', //Amazon Signing Algorithm, Optional: uses AMZN-PAY-RSASSA-PSS if not specified 'integrator_id' => 'AXXXXXXXXXXXXX', // (optional) Solution Provider Platform Id in Amz UID Format 'integrator_version' => '1.2.3', // (optional) Solution Provider Plugin Version in Semantic Versioning Format 'platform_version' => '0.0.4', // (optional) Solution Provider Platform Version in Semantic Versioning Format 'proxy' => [ 'host' => 'proxy_host', 'port' => 'proxy_port', 'username' => 'proxy_username', 'password' => 'proxy_password', ] );
版本控制
pay-api.amazon.com|eu|jp 端点使用版本控制来允许未来的更新。此 SDK 的主要版本将与端点的 API 版本保持一致。
如果您已下载 1.x.y 版本的此 SDK,下面的示例中的 $version 将是 "v1"。2.x.y 将是 "v2",等等。
便捷函数(概述)
利用内置的便捷函数轻松进行 API 调用。向下滚动以查看示例代码片段。
使用便捷函数时,请求有效载荷将使用提供的私有密钥进行签名,并使用 HTTPS 请求向正确的区域端点进行请求。如果发生请求限制,将使用指数退避方法尝试 HTTPS 调用最多三次。
Alexa 配送跟踪器 API
使用此 API 向 Amazon Pay 提供运输跟踪信息,以便 Amazon Pay 在发货和交付时通过 Alexa 通知买家。有关更多信息,请参阅配送跟踪器 API 文档。
- deliveryTrackers($payload, $headers = null) → POST 到 "$version/deliveryTrackers"
授权令牌 API
请注意,您的解决方案提供商帐户必须与商户帐户存在预建立的关系(有效的和有效的 MWS 授权令牌),才能使用此功能。
- getAuthorizationToken($mwsAuthToken, $merchantId, $headers = null) → 通过 GET 请求到 "$version/authorizationTokens/$mwsAuthToken?merchantId=$merchantId"
Amazon Checkout v2 API
下面的创建/POST调用中,$headers字段不是可选的,因为它至少需要x-amz-pay-idempotency-key头部
$headers = array('x-amz-pay-idempotency-key' => uniqid());
Amazon Checkout v2买家对象
- getBuyer($buyerToken, $headers = null) → 通过 GET 请求到 "$version/buyers/$buyerToken"
Amazon Checkout v2结账会话对象
- createCheckoutSession($payload, $headers) → 通过 POST 请求到 "$version/checkoutSessions"
- getCheckoutSession($checkoutSessionId, $headers = null) → 通过 GET 请求到 "$version/checkoutSessions/$checkoutSessionId"
- updateCheckoutSession($checkoutSessionId, $payload, $headers = null) → 通过 PATCH 请求到 "$version/checkoutSessions/$checkoutSessionId"
- completeCheckoutSession($checkoutSessionId, $payload, $headers = null) → 通过 POST 请求到 "$version/checkoutSessions/$checkoutSessionId/complete"
Amazon Checkout v2收费权限对象
- getChargePermission($chargePermissionId, $headers = null) → 通过 GET 请求到 "$version/chargePermissions/$chargePermissionId"
- updateChargePermission($chargePermissionId, $payload, $headers = null) → 通过 PATCH 请求到 "$version/chargePermissions/$chargePermissionId"
- closeChargePermission($chargePermissionId, $payload, $headers = null) → 通过 DELETE 请求到 "$version/chargePermissions/$chargePermissionId/close"
Amazon Checkout v2收费对象
- createCharge($payload, $headers) → 通过 POST 请求到 "$version/charges"
- getCharge($chargeId, $headers = null) → 通过 GET 请求到 "$version/charges/$chargeId"
- captureCharge($chargeId, $payload, $headers) → 通过 POST 请求到 "$version/charges/$chargeId/capture"
- cancelCharge($chargeId, $payload, $headers = null) → 通过 DELETE 请求到 "$version/charges/$chargeId/cancel"
Amazon Checkout v2退款对象
- createRefund($payload, $headers) → 通过 POST 请求到 "$version/refunds"
- getRefund($refundId, $headers = null) → 通过 GET 请求到 "$version/refunds/$refundId"
店内API
在生产环境中使用店内API调用之前,请联系您的Amazon Pay账户经理以获取店内集成指南的副本。
- instoreMerchantScan($payload, $headers = null) → 通过 POST 请求到 "$version/in-store/merchantScan"
- instoreCharge($payload, $headers = null) → 通过 POST 请求到 "$version/in-store/charge"
- instoreRefund($payload, $headers = null) → 通过 POST 请求到 "$version/in-store/refund"
Amazon Checkout v2 SPC
- finalizeCheckoutSession($checkoutSessionId, $payload, $headers = null) → 通过 POST 请求到 "$version/checkoutSessions/$checkoutSessionId/finalize"
Amazon Checkout v2商家入驻和账户管理对象
- registerAmazonPayAccount($payload, $headers = null) → 通过 POST 请求到 "$version/merchantAccounts"
- updateAmazonPayAccount($merchantAccountId, $payload, $headers = null) → 通过 PATCH 请求到 "$version/merchantAccounts/$merchantAccountId"
- deleteAmazonPayAccount($merchantAccountId, $headers = null) → 通过 DELETE 请求到 "$version/merchantAccounts/$merchantAccountId"
Amazon Checkout v2账户管理API
- createMerchantAccount($payload, $headers) → 通过 POST 请求到 "$version/merchantAccounts"
- updateMerchantAccount($merchantAccountId, $payload, $headers) → 通过 PATCH 请求到 "$version/merchantAccounts/$merchantAccountId"
- claimMerchantAccount($merchantAccountId, $payload, $headers) → 通过 POST 请求到 "$version/merchantAccounts/$merchantAccountId/claim"
使用便捷函数
进行API调用需要四个简单步骤
步骤1. 构建一个客户端(使用之前定义的配置数组)。
$client = new Amazon\Pay\API\Client($amazonpay_config);
步骤2. 生成有效负载。
$payload = '{"scanData":"UKhrmatMeKdlfY6b","scanReferenceId":"0b8fb271-2ae2-49a5-b35d7","merchantCOE":"US","ledgerCurrency":"USD","chargeTotal":{"currencyCode":"USD","amount":"2.00"},"metadata":{"merchantNote":"Merchant Name","communicationContext":{"merchantStoreName":"Store Name","merchantOrderId":"789123"}}}';
步骤3. 执行调用。
$result = $client->instoreMerchantScan($payload);
步骤4. 检查结果。
$result将是一个数组,包含以下键
- 'status' - 整数HTTP状态码(200,201等)
- 'response' - JSON响应正文
- 'request_id' - 来自Amazon API网关的请求ID
- 'url' - SDK调用的REST调用的URL,用于故障排除目的
- 'method - POST,GET,PATCH或DELETE
- 'headers' - 包含由SDK生成的各种头部的数组,用于故障排除目的
- 'request' - JSON请求有效负载
- ‘重试次数’ - 通常为0,但反映由于限流或其他服务器问题而重试请求的次数
- ‘持续时间’ - SDK函数调用的毫秒数
前两项(状态,响应)是关键的。其余项在故障排除情况下很有用。
在PHP中解析响应,您可以使用PHP的json_decode()函数
$response = json_decode($result['response'], true); $id = $response['chargePermissionId'];
如果您是解决方案提供商,需要代表不同的商户账户进行API调用,您需要在API调用中传递额外的身份验证令牌参数。
$headers = array('x-amz-pay-authtoken' => 'other_merchant_super_secret_token'); $result = $client->instoreMerchantScan($payload, $headers);
第二步的一个替代方法是可以使用PHP数组并程序化生成JSON有效载荷
$payload = array( 'scanData' => 'UKhrmatMeKdlfY6b', 'scanReferenceId' => uniqid(), 'merchantCOE' => 'US', 'ledgerCurrency' => 'USD', 'chargeTotal' => array( 'currencyCode' => 'USD', 'amount' => '2.00' ), 'metadata' => array( 'merchantNote' => 'Merchant Name', 'communicationContext' => array( 'merchantStoreName' => 'Store Name', 'merchantOrderId' => '789123' ) ) ); $payload = json_encode($payload);
便利函数代码示例
Alexa配送通知
<?php include 'vendor/autoload.php'; $amazonpay_config = array( 'public_key_id' => 'MY_PUBLIC_KEY_ID', 'private_key' => 'keys/private.pem', 'region' => 'US', 'sandbox' => false, 'algorithm' => 'AMZN-PAY-RSASSA-PSS-V2', ); $payload = array( 'amazonOrderReferenceId' => 'P01-0000000-0000000', 'deliveryDetails' => array(array( 'trackingNumber' => '01234567890', 'carrierCode' => 'FEDEX' )) ); try { $client = new Amazon\Pay\API\Client($amazonpay_config); $result = $client->deliveryTrackers($payload); if ($result['status'] === 200) { // success echo $result['response'] . "\n"; } else { // check the error echo 'status=' . $result['status'] . '; response=' . $result['response'] . "\n"; } } catch (\Exception $e) { // handle the exception echo $e . "\n"; } ?>
Amazon Checkout v2 - 创建结账会话(AJAX服务示例)
<?php session_start(); include 'vendor/autoload.php'; $amazonpay_config = array( 'public_key_id' => 'MY_PUBLIC_KEY_ID', 'private_key' => 'keys/private.pem', 'region' => 'US', 'sandbox' => true, 'algorithm' => 'AMZN-PAY-RSASSA-PSS-V2', 'integrator_id' => 'AXXXXXXXXXXXXX', // (optional) Solution Provider Platform Id in Amz UID Format 'integrator_version' => '1.2.3', // (optional) Solution Provider Plugin Version in Semantic Versioning Format 'platform_version' => '0.0.4' // (optional) Solution Provider Platform Version in Semantic Versioning Format ); $payload = array( 'webCheckoutDetails' => array( 'checkoutReviewReturnUrl' => 'https://localhost/store/checkout_review', 'checkoutResultReturnUrl' => 'https://localhost/store/checkout_result' ), 'storeId' => 'amzn1.application-oa2-client.000000000000000000000000000000000' ); $headers = array('x-amz-pay-Idempotency-Key' => uniqid()); try { $client = new Amazon\Pay\API\Client($amazonpay_config); $result = $client->createCheckoutSession($payload, $headers); header("Content-type:application/json; charset=utf-8"); echo $result['response']; if ($result['status'] !== 201) { http_response_code(500); } } catch (\Exception $e) { // handle the exception echo $e . "\n"; http_response_code(500); } ?>
Amazon Checkout v2 - 创建结账会话(独立脚本示例)
<?php include 'vendor/autoload.php'; $amazonpay_config = array( 'public_key_id' => 'YOUR_PUBLIC_KEY_ID', 'private_key' => 'keys/private.pem', // Path to RSA Private Key (or a string representation) 'region' => 'YOUR_REGION_CODE', 'sandbox' => true, 'algorithm' => 'AMZN-PAY-RSASSA-PSS-V2', 'integrator_id' => 'AXXXXXXXXXXXXX', // (optional) Solution Provider Platform Id in Amz UID Format 'integrator_version' => '1.2.3', // (optional) Solution Provider Plugin Version in Semantic Versioning Format 'platform_version' => '0.0.4' // (optional) Solution Provider Platform Version in Semantic Versioning Format ); $payload = array( 'webCheckoutDetails' => array( 'checkoutReviewReturnUrl' => 'https://localhost/store/checkout_review', 'checkoutResultReturnUrl' => 'https://localhost/store/checkout_result' ), 'storeId' => 'amzn1.application-oa2-client.000000000000000000000000000000000' ); $headers = array('x-amz-pay-Idempotency-Key' => uniqid()); try { $client = new Amazon\Pay\API\Client($amazonpay_config); $result = $client->createCheckoutSession($payload, $headers); if ($result['status'] === 201) { // created $response = json_decode($result['response'], true); $checkoutSessionId = $response['checkoutSessionId']; echo "checkoutSessionId=$checkoutSessionId\n"; } else { // check the error echo 'status=' . $result['status'] . '; response=' . $result['response'] . "\n"; } } catch (\Exception $e) { // handle the exception echo $e . "\n"; } ?>
Amazon Checkout v2 - 获取结账会话
<?php include 'vendor/autoload.php'; $amazonpay_config = array( 'public_key_id' => 'YOUR_PUBLIC_KEY_ID', 'private_key' => 'keys/private.pem', // Path to RSA Private Key (or a string representation) 'region' => 'YOUR_REGION_CODE', 'sandbox' => true, 'algorithm' => 'AMZN-PAY-RSASSA-PSS-V2', 'integrator_id' => 'AXXXXXXXXXXXXX', // (optional) Solution Provider Platform Id in Amz UID Format 'integrator_version' => '1.2.3', // (optional) Solution Provider Plugin Version in Semantic Versioning Format 'platform_version' => '0.0.4' // (optional) Solution Provider Platform Version in Semantic Versioning Format ); try { $checkoutSessionId = '00000000-0000-0000-0000-000000000000'; $client = new Amazon\Pay\API\Client($amazonpay_config); $result = $client->getCheckoutSession($checkoutSessionId); if ($result['status'] === 200) { $response = json_decode($result['response'], true); $checkoutSessionState = $response['statusDetails']['state']; $chargeId = $response['chargeId']; $chargePermissionId = $response['chargePermissionId']; // NOTE: Once Checkout Session moves to a "Completed" state, buyer and shipping // details must be obtained from the getCharges() function call instead $buyerName = $response['buyer']['name']; $buyerEmail = $response['buyer']['email']; $shipName = $response['shippingAddress']['name']; $shipAddrLine1 = $response['shippingAddress']['addressLine1']; $shipCity = $response['shippingAddress']['city']; $shipState = $response['shippingAddress']['stateOrRegion']; $shipZip = $response['shippingAddress']['postalCode']; $shipCounty = $response['shippingAddress']['countryCode']; echo "checkoutSessionState=$checkoutSessionState\n"; echo "chargeId=$chargeId; chargePermissionId=$chargePermissionId\n"; echo "buyer=$buyerName ($buyerEmail)\n"; echo "shipName=$shipName\n"; echo "address=$shipAddrLine1; $shipCity $shipState $shipZip ($shipCounty)\n"; } else { // check the error echo 'status=' . $result['status'] . '; response=' . $result['response'] . "\n"; } } catch (\Exception $e) { // handle the exception echo $e . "\n"; } ?>
Amazon Checkout v2 - 更新结账会话
<?php include 'vendor/autoload.php'; $amazonpay_config = array( 'public_key_id' => 'YOUR_PUBLIC_KEY_ID', 'private_key' => 'keys/private.pem', // Path to RSA Private Key (or a string representation) 'region' => 'YOUR_REGION_CODE', 'sandbox' => true, 'algorithm' => 'AMZN-PAY-RSASSA-PSS-V2', 'integrator_id' => 'AXXXXXXXXXXXXX', // (optional) Solution Provider Platform Id in Amz UID Format 'integrator_version' => '1.2.3', // (optional) Solution Provider Plugin Version in Semantic Versioning Format 'platform_version' => '0.0.4' // (optional) Solution Provider Platform Version in Semantic Versioning Format ); $payload = array( 'paymentDetails' => array( 'paymentIntent' => 'Authorize', 'canHandlePendingAuthorization' => false, 'chargeAmount' => array( 'amount' => '1.23', 'currencyCode' => 'USD' ), ), 'merchantMetadata' => array( 'merchantReferenceId' => '2020-00000001', 'merchantStoreName' => 'Store Name', 'noteToBuyer' => 'Thank you for your order!' ) ); try { $checkoutSessionId = '00000000-0000-0000-0000-000000000000'; $client = new Amazon\Pay\API\Client($amazonpay_config); $result = $client->updateCheckoutSession($checkoutSessionId, $payload); if ($result['status'] === 200) { $response = json_decode($result['response'], true); $amazonPayRedirectUrl = $response['webCheckoutDetails']['amazonPayRedirectUrl']; echo "amazonPayRedirectUrl=$amazonPayRedirectUrl\n"; } else { // check the error echo 'status=' . $result['status'] . '; response=' . $result['response'] . "\n"; } } catch (\Exception $e) { // handle the exception echo $e . "\n"; } ?>
Amazon Checkout v2 - 完成结账会话API
<?php include 'vendor/autoload.php'; $amazonpay_config = array( 'public_key_id' => 'YOUR_PUBLIC_KEY_ID', 'private_key' => 'keys/private.pem', // Path to RSA Private Key (or a string representation) 'region' => 'YOUR_REGION_CODE', 'sandbox' => true, 'algorithm' => 'AMZN-PAY-RSASSA-PSS-V2', 'integrator_id' => 'AXXXXXXXXXXXXX', // (optional) Solution Provider Platform Id in Amz UID Format 'integrator_version' => '1.2.3', // (optional) Solution Provider Plugin Version in Semantic Versioning Format 'platform_version' => '0.0.4' // (optional) Solution Provider Platform Version in Semantic Versioning Format ); $payload = array( 'chargeAmount' => array( 'amount' => '14.00', 'currencyCode' => 'USD' ) ); try { $checkoutSessionId = '00000000-0000-0000-0000-000000000000'; $client = new Amazon\Pay\API\Client($amazonpay_config); $result = $client->completeCheckoutSession($checkoutSessionId, $payload); if ($result['status'] === 202) { // Charge Permission is in AuthorizationInitiated state $response = json_decode($result['response'], true); $checkoutSessionState = $response['statusDetails']['state']; $chargeId = $response['chargeId']; $chargePermissionId = $response['chargePermissionId']; } else if ($result['status'] === 200) { $response = json_decode($result['response'], true); $checkoutSessionState = $response['statusDetails']['state']; $chargePermissionId = $response['chargePermissionId']; } else { // check the error echo 'status=' . $result['status'] . '; response=' . $result['response'] . "\n"; } } catch (Exception $e) { // handle the exception echo $e; } ?>
Amazon Checkout v2 - 获取扣款权限API
<?php include 'vendor/autoload.php'; $amazonpay_config = array( 'public_key_id' => 'YOUR_PUBLIC_KEY_ID', 'private_key' => 'keys/private.pem', // Path to RSA Private Key (or a string representation) 'region' => 'YOUR_REGION_CODE', 'sandbox' => true, 'algorithm' => 'AMZN-PAY-RSASSA-PSS-V2', 'integrator_id' => 'AXXXXXXXXXXXXX', // (optional) Solution Provider Platform Id in Amz UID Format 'integrator_version' => '1.2.3', // (optional) Solution Provider Plugin Version in Semantic Versioning Format 'platform_version' => '0.0.4' // (optional) Solution Provider Platform Version in Semantic Versioning Format ); try { $chargePermissionId = 'S01-0000000-0000000'; $client = new Amazon\Pay\API\Client($amazonpay_config); $result = $client->getChargePermission($chargePermissionId); if ($result['status'] === 200) { $response = json_decode($result['response'], true); $chargePermissionState = $response['statusDetails']['state']; } else { // check the error echo 'status=' . $result['status'] . '; response=' . $result['response']; } } catch (Exception $e) { // handle the exception echo $e; } ?>
Amazon Checkout v2 - 更新扣款权限API
<?php include 'vendor/autoload.php'; $amazonpay_config = array( 'public_key_id' => 'YOUR_PUBLIC_KEY_ID', 'private_key' => 'keys/private.pem', // Path to RSA Private Key (or a string representation) 'region' => 'YOUR_REGION_CODE', 'sandbox' => true, 'algorithm' => 'AMZN-PAY-RSASSA-PSS-V2', 'integrator_id' => 'AXXXXXXXXXXXXX', // (optional) Solution Provider Platform Id in Amz UID Format 'integrator_version' => '1.2.3', // (optional) Solution Provider Plugin Version in Semantic Versioning Format 'platform_version' => '0.0.4' // (optional) Solution Provider Platform Version in Semantic Versioning Format ); $payload = array( 'merchantMetadata' => array( 'merchantReferenceId' => '32-41-323141-32', 'merchantStoreName' => 'AmazonTestStoreFront', 'noteToBuyer' => 'Some Note to buyer', 'customInformation' => '' ) ); try { $chargePermissionId = 'S01-0000000-0000000'; $client = new Amazon\Pay\API\Client($amazonpay_config); $result = $client->updateChargePermission($chargePermissionId, $payload); if ($result['status'] === 200) { $response = json_decode($result['response'], true); } else { // check the error echo 'status=' . $result['status'] . '; response=' . $result['response']; } } catch (Exception $e) { // handle the exception echo $e; } ?>
Amazon Checkout v2 - 关闭扣款权限API
<?php include 'vendor/autoload.php'; $amazonpay_config = array( 'public_key_id' => 'YOUR_PUBLIC_KEY_ID', 'private_key' => 'keys/private.pem', // Path to RSA Private Key (or a string representation) 'region' => 'YOUR_REGION_CODE', 'sandbox' => true, 'algorithm' => 'AMZN-PAY-RSASSA-PSS-V2', 'integrator_id' => 'AXXXXXXXXXXXXX', // (optional) Solution Provider Platform Id in Amz UID Format 'integrator_version' => '1.2.3', // (optional) Solution Provider Plugin Version in Semantic Versioning Format 'platform_version' => '0.0.4' // (optional) Solution Provider Platform Version in Semantic Versioning Format ); $payload = array( 'closureReason' => 'No more charges required', 'cancelPendingCharges' => false ); try { $chargePermissionId = 'S01-0000000-0000000'; $client = new Amazon\Pay\API\Client($amazonpay_config); $result = $client->closeChargePermission($chargePermissionId, $payload); if ($result['status'] === 200) { $response = json_decode($result['response'], true); $chargePermissionState = $response['statusDetails']['state']; } else { // check the error echo 'status=' . $result['status'] . '; response=' . $result['response']; } } catch (Exception $e) { // handle the exception echo $e; } ?>
Amazon Checkout v2 - 创建扣款API
<?php include 'vendor/autoload.php'; $amazonpay_config = array( 'public_key_id' => 'YOUR_PUBLIC_KEY_ID', 'private_key' => 'keys/private.pem', // Path to RSA Private Key (or a string representation) 'region' => 'YOUR_REGION_CODE', 'algorithm' => 'AMZN-PAY-RSASSA-PSS-V2', 'sandbox' => true, 'integrator_id' => 'AXXXXXXXXXXXXX', // (optional) Solution Provider Platform Id in Amz UID Format 'integrator_version' => '1.2.3', // (optional) Solution Provider Plugin Version in Semantic Versioning Format 'platform_version' => '0.0.4' // (optional) Solution Provider Platform Version in Semantic Versioning Format ); $payload = array( 'chargePermissionId' => 'S01-0000000-0000000', 'chargeAmount' => array( 'amount' => '14.00', 'currencyCode' => 'USD' ), 'captureNow' => true, 'softDescriptor' => 'Descriptor', 'canHandlePendingAuthorization' => false ); $headers = array('x-amz-pay-Idempotency-Key' => uniqid()); try { $client = new Amazon\Pay\API\Client($amazonpay_config); $result = $client->createCharge($payload, $headers); if ($result['status'] === 201) { $response = json_decode($result['response'], true); $chargeState = $response['statusDetails']['state']; $chargeId = $response['chargeId']; } else { // check the error echo 'status=' . $result['status'] . '; response=' . $result['response']; } } catch (Exception $e) { // handle the exception echo $e; } ?>
Amazon Checkout v2 - 获取扣款API
<?php include 'vendor/autoload.php'; $amazonpay_config = array( 'public_key_id' => 'YOUR_PUBLIC_KEY_ID', 'private_key' => 'keys/private.pem', // Path to RSA Private Key (or a string representation) 'region' => 'YOUR_REGION_CODE', 'algorithm' => 'AMZN-PAY-RSASSA-PSS-V2', 'sandbox' => true, 'integrator_id' => 'AXXXXXXXXXXXXX', // (optional) Solution Provider Platform Id in Amz UID Format 'integrator_version' => '1.2.3', // (optional) Solution Provider Plugin Version in Semantic Versioning Format 'platform_version' => '0.0.4' // (optional) Solution Provider Platform Version in Semantic Versioning Format ); try { $chargeId = 'S01-0000000-0000000-C000000'; $client = new Amazon\Pay\API\Client($amazonpay_config); $result = $client->getCharge($chargeId); if ($result['status'] === 200) { $response = json_decode($result['response'], true); $chargeState = $response['statusDetails']['state']; } else { // check the error echo 'status=' . $result['status'] . '; response=' . $result['response']; } } catch (Exception $e) { // handle the exception echo $e; } ?>
Amazon Checkout v2 - 扣款API
<?php include 'vendor/autoload.php'; $amazonpay_config = array( 'public_key_id' => 'YOUR_PUBLIC_KEY_ID', 'private_key' => 'keys/private.pem', // Path to RSA Private Key (or a string representation) 'region' => 'YOUR_REGION_CODE', 'sandbox' => true, 'algorithm' => 'AMZN-PAY-RSASSA-PSS-V2', 'integrator_id' => 'AXXXXXXXXXXXXX', // (optional) Solution Provider Platform Id in Amz UID Format 'integrator_version' => '1.2.3', // (optional) Solution Provider Plugin Version in Semantic Versioning Format 'platform_version' => '0.0.4' // (optional) Solution Provider Platform Version in Semantic Versioning Format ); $payload = array( 'captureAmount' => array( 'amount' => '1.23', 'currencyCode' => 'USD' ), 'softDescriptor' => 'For CC Statement' ); try { $chargeId = 'S01-0000000-0000000-C000000'; $headers = array('x-amz-pay-Idempotency-Key' => uniqid()); $client = new Amazon\Pay\API\Client($amazonpay_config); $result = $client->captureCharge($chargeId, $payload, $headers); if ($result['status'] === 200) { $response = json_decode($result['response'], true); $state = $response['statusDetails']['state']; $reasonCode = $response['statusDetails']['reasonCode']; $reasonDescription = $response['statusDetails']['reasonDescription']; echo "state=$state; reasonCode=$reasonCode; reasonDescription=$reasonDescription\n"; } else { // check the error echo 'status=' . $result['status'] . '; response=' . $result['response'] . "\n"; } } catch (\Exception $e) { // handle the exception echo $e . "\n"; } ?>
Amazon Checkout v2 - 取消扣款API
<?php include 'vendor/autoload.php'; $amazonpay_config = array( 'public_key_id' => 'YOUR_PUBLIC_KEY_ID', 'private_key' => 'keys/private.pem', // Path to RSA Private Key (or a string representation) 'region' => 'YOUR_REGION_CODE', 'algorithm' => 'AMZN-PAY-RSASSA-PSS-V2', 'sandbox' => true, 'algorithm' => 'AMZN-PAY-RSASSA-PSS-V2', 'integrator_id' => 'AXXXXXXXXXXXXX', // (optional) Solution Provider Platform Id in Amz UID Format 'integrator_version' => '1.2.3', // (optional) Solution Provider Plugin Version in Semantic Versioning Format 'platform_version' => '0.0.4' // (optional) Solution Provider Platform Version in Semantic Versioning Format ); $payload = array( 'cancellationReason' => 'REASON DESCRIPTION' ); try { $chargeId = 'S01-0000000-0000000-C000000'; $client = new Amazon\Pay\API\Client($amazonpay_config); $result = $client->cancelCharge($chargeId, $payload); if ($result['status'] === 200) { $response = json_decode($result['response'], true); $chargeState = $response['statusDetails']['state']; } else { // check the error echo 'status=' . $result['status'] . '; response=' . $result['response']; } } catch (Exception $e) { // handle the exception echo $e; } ?>
Amazon Checkout v2 - 创建退款API
<?php include 'vendor/autoload.php'; $amazonpay_config = array( 'public_key_id' => 'YOUR_PUBLIC_KEY_ID', 'private_key' => 'keys/private.pem', // Path to RSA Private Key (or a string representation) 'region' => 'YOUR_REGION_CODE', 'algorithm' => 'AMZN-PAY-RSASSA-PSS-V2', 'sandbox' => true, 'algorithm' => 'AMZN-PAY-RSASSA-PSS-V2', 'integrator_id' => 'AXXXXXXXXXXXXX', // (optional) Solution Provider Platform Id in Amz UID Format 'integrator_version' => '1.2.3', // (optional) Solution Provider Plugin Version in Semantic Versioning Format 'platform_version' => '0.0.4' // (optional) Solution Provider Platform Version in Semantic Versioning Format ); $payload = array( 'chargeId' => 'S01-0000000-0000000-C000000', 'refundAmount' => array( 'amount' => '14.00', 'currencyCode' => 'USD' ), 'softDescriptor' => 'Descriptor' ); $headers = array('x-amz-pay-Idempotency-Key' => uniqid()); try { $client = new Amazon\Pay\API\Client($amazonpay_config); $result = $client->createRefund($payload, $headers); if ($result['status'] === 201) { $response = json_decode($result['response'], true); $refundState = $response['statusDetails']['state']; $refundId = $response['refundId']; } else { // check the error echo 'status=' . $result['status'] . '; response=' . $result['response']; } } catch (Exception $e) { // handle the exception echo $e; } ?>
Amazon Checkout v2 - 获取退款API
<?php include 'vendor/autoload.php'; $amazonpay_config = array( 'public_key_id' => 'YOUR_PUBLIC_KEY_ID', 'private_key' => 'keys/private.pem', // Path to RSA Private Key (or a string representation) 'region' => 'YOUR_REGION_CODE', 'algorithm' => 'AMZN-PAY-RSASSA-PSS-V2', 'sandbox' => true, 'algorithm' => 'AMZN-PAY-RSASSA-PSS-V2', 'integrator_id' => 'AXXXXXXXXXXXXX', // (optional) Solution Provider Platform Id in Amz UID Format 'integrator_version' => '1.2.3', // (optional) Solution Provider Plugin Version in Semantic Versioning Format 'platform_version' => '0.0.4' // (optional) Solution Provider Platform Version in Semantic Versioning Format ); try { $refundId = 'S01-0000000-0000000-R000000' $client = new Amazon\Pay\API\Client($amazonpay_config); $result = $client->getRefund($refundId); if ($result['status'] === 200) { $response = json_decode($result['response'], true); $chargeState = $response['statusDetails']['state']; } else { // check the error echo 'status=' . $result['status'] . '; response=' . $result['response']; } } catch (Exception $e) { // handle the exception echo $e; } ?>
Amazon Checkout v2 - 获取买家API
<?php include 'vendor/autoload.php'; $amazonpay_config = array( 'public_key_id' => 'YOUR_PUBLIC_KEY_ID', 'private_key' => 'keys/private.pem', // Path to RSA Private Key (or a string representation) 'region' => 'YOUR_REGION_CODE', 'algorithm' => 'AMZN-PAY-RSASSA-PSS-V2', 'sandbox' => true, 'algorithm' => 'AMZN-PAY-RSASSA-PSS-V2', 'integrator_id' => 'AXXXXXXXXXXXXX', // (optional) Solution Provider Platform Id in Amz UID Format 'integrator_version' => '1.2.3', // (optional) Solution Provider Plugin Version in Semantic Versioning Format 'platform_version' => '0.0.4' // (optional) Solution Provider Platform Version in Semantic Versioning Format ); try { $buyerToken = 'BUYER_TOKEN'; $client = new Amazon\Pay\API\Client($amazonpay_config); $result = $client->getBuyer($buyerToken); if ($result['status'] === 200) { $response = json_decode($result['response'], true); } else { // check the error echo 'status=' . $result['status'] . '; response=' . $result['response']; } } catch (Exception $e) { // handle the exception echo $e; } ?>
生成按钮签名(辅助函数)
此辅助函数生成的签名仅适用于Checkout v2前端按钮。与API签名不同,不涉及时间戳,因此此函数的结果可以被视为静态签名,可以安全地放置在您的网站JS源文件中并重复使用(只要您的有效载荷没有变化)。
<?php include 'vendor/autoload.php'; $amazonpay_config = array( 'public_key_id' => 'MY_PUBLIC_KEY_ID', 'private_key' => 'keys/private.pem', 'region' => 'US', 'sandbox' => true, 'algorithm' => 'AMZN-PAY-RSASSA-PSS-V2', ); $client = new Amazon\Pay\API\Client($amazonpay_config); $payload = '{"storeId":"amzn1.application-oa2-client.xxxxx","webCheckoutDetails":{"checkoutReviewReturnUrl":"https://localhost/test/CheckoutReview.php","checkoutResultReturnUrl":"https://localhost/test/CheckoutResult.php"}}'; $signature = $client->generateButtonSignature($payload); echo $signature . "\n"; ?>
手动签名(仅限高级用例)
此SDK提供帮助您手动签名API请求的能力,如果您想使用自己的代码通过互联网发送HTTPS请求。
带有值的getPostSignedHeaders函数调用示例
/* getPostSignedHeaders convenience – Takes values for canonical request sorts and parses it and * returns a signature for the request being sent * @param $http_request_method [String] * @param $request_uri [String] * @param $request_parameters [array()] * @param $request_payload [string] */
示例请求方法
$method = 'POST'; // API Merchant Scan $url = 'https://pay-api.amazon.com/sandbox/' . $versiom . '/in-store/merchantScan'; $payload = array( 'scanData' => 'UKhrmatMeKdlfY6b', 'scanReferenceId' => '0b8fb271-2ae2-49a5-b35d4', 'merchantCOE' => 'US', 'ledgerCurrency' => 'USD', 'chargeTotal' => array( 'currencyCode' => 'USD', 'amount' => '2.00' ), 'metadata' => array( 'merchantNote' => 'Ice Cream', 'customInformation' => 'In-store Ice Cream', 'communicationContext' => array( 'merchantStoreName' => 'Store Name', 'merchantOrderId' => '789123' ) ) ); // Convert to json string $payload = json_encode($payload); $requestParameters = array(); $client = new Amazon\Pay\API\Client($amazonpay_config); $postSignedHeaders = $client->getPostSignedHeaders($method, $url, $requestParameters, $payload);
带有值的createSignature函数调用示例
(这仅在您不使用getPostSignedHeaders并想创建自己的自定义头时使用。)
/* createSignature convenience – Takes values for canonical request sorts and parses it and * returns a signature for the request being sent * @param $http_request_method [String] * @param $request_uri [String] * @param $request_parameters [Array()] * @param $pre_signed_headers [Array()] * @param $request_payload [String] * @param $timeStamp [String] */ // Example request method: $method = 'POST'; // API Merchant Scan $url = 'https://pay-api.amazon.com/sandbox/in-store/' . $version . '/merchantScan'; $payload = array( 'scanData' => 'ScanData', 'scanReferenceId' => '0b8fb271-2ae2-49a5-b35d4', 'merchantCOE' => 'US', 'ledgerCurrency' => 'USD', 'chargeTotal' => array( 'currencyCode' => 'USD', 'amount' => '2.00' ), 'metadata' => array( 'merchantNote' => 'Ice Cream', 'customInformation' => 'In-store Ice Cream', 'communicationContext' => array( 'merchantStoreName' => 'Store Name', 'merchantOrderId' => '789123' ) ) ); // Convert to json string $payload = json_encode($payload); $requestParameters = array(); $client = new Amazon\Pay\API\Client($amazonpay_config); // Create an array that will contain the parameters for the charge API call $pre_signed_headers = array(); $pre_signed_headers['Accept'] = 'application/json'; $pre_signed_headers['Content-Type'] = 'application/json'; $pre_signed_headers['X-Amz-Pay-Region'] = 'na'; $client = new Client($amazonpay_config); $signedInput = $client->createSignature($method, $url, $requestParameters, $pre_signed_headers, $payload, '20180326T203730Z');
报告API代码示例
Amazon Checkout v2报告API - 获取报告API
<?php include 'vendor/autoload.php'; $amazonpay_config = array( 'public_key_id' => 'MY_PUBLIC_KEY_ID', 'private_key' => 'keys/private.pem', 'region' => 'US', 'sandbox' => false ); $requestPayload = array( 'reportTypes' => '_GET_FLAT_FILE_OFFAMAZONPAYMENTS_ORDER_REFERENCE_DATA_', 'processingStatuses' => 'COMPLETED', 'pageSize' => '10' ); try { $client = new Amazon\Pay\API\Client($amazonpay_config); $result = $client->getReports($requestPayload); if ($result['status'] === 200) { // success $response = $result['response']; echo $response; } else { // check the error echo 'status=' . $result['status'] . '; response=' . $result['response'] . "\n"; } } catch (\Exception $e) { // handle the exception echo $e . "\n"; } ?>
Amazon Checkout v2报告API - 通过ID获取报告API
<?php include 'vendor/autoload.php'; $amazonpay_config = array( 'public_key_id' => 'MY_PUBLIC_KEY_ID', 'private_key' => 'keys/private.pem', 'region' => 'US', 'sandbox' => true ); try { $reportId = "1234567890"; $client = new Amazon\Pay\API\Client($amazonpay_config); $result = $client->getReportById($reportId); if ($result['status'] === 200) { // success $response = $result['response']; echo $response; } else { // check the error echo 'status=' . $result['status'] . '; response=' . $result['response'] . "\n"; } } catch (\Exception $e) { // handle the exception echo $e . "\n"; } ?>
Amazon Checkout v2报告API - 获取报告文档API
<?php include 'vendor/autoload.php'; $amazonpay_config = array( 'public_key_id' => 'MY_PUBLIC_KEY_ID', 'private_key' => 'keys/private.pem', 'region' => 'US', 'sandbox' => true ); try { $reportDocumentId = "amzn1.tortuga.0.000000000-0000-0000-0000-000000000000.00000000000000"; $client = new Amazon\Pay\API\Client($amazonpay_config); $result = $client->getReportDocument($reportDocumentId); if ($result['status'] === 200) { // success $response = $result['response']; echo $response; } else { // check the error echo 'status=' . $result['status'] . '; response=' . $result['response'] . "\n"; } } catch (\Exception $e) { // handle the exception echo $e . "\n"; } ?>
Amazon Checkout v2报告API - 获取报告计划API
<?php include 'vendor/autoload.php'; $amazonpay_config = array( 'public_key_id' => 'MY_PUBLIC_KEY_ID', 'private_key' => 'keys/private.pem', 'region' => 'US', 'sandbox' => true ); try { $reportTypes = "_GET_FLAT_FILE_OFFAMAZONPAYMENTS_ORDER_REFERENCE_DATA_,_GET_FLAT_FILE_OFFAMAZONPAYMENTS_BILLING_AGREEMENT_DATA_"; $client = new Amazon\Pay\API\Client($amazonpay_config); $result = $client->getReportSchedules($reportTypes); if ($result['status'] === 200) { // success $response = $result['response']; echo $response; } else { // check the error echo 'status=' . $result['status'] . '; response=' . $result['response'] . "\n"; } } catch (\Exception $e) { // handle the exception echo $e . "\n"; } ?>
Amazon Checkout v2报告API - 通过ID获取报告计划API
<?php include 'vendor/autoload.php'; $amazonpay_config = array( 'public_key_id' => 'MY_PUBLIC_KEY_ID', 'private_key' => 'keys/private.pem', 'region' => 'US', 'sandbox' => true ); try { $reportScheduleId = "1234567890"; $client = new Amazon\Pay\API\Client($amazonpay_config); $result = $client->getReportScheduleById($reportScheduleId); if ($result['status'] === 200) { // success $response = $result['response']; echo $response; } else { // check the error echo 'status=' . $result['status'] . '; response=' . $result['response'] . "\n"; } } catch (\Exception $e) { // handle the exception echo $e . "\n"; } ?>
Amazon Checkout v2报告API - 创建报告API
<?php include 'vendor/autoload.php'; $amazonpay_config = array( 'public_key_id' => 'MY_PUBLIC_KEY_ID', 'private_key' => 'keys/private.pem', 'region' => 'US', 'sandbox' => true ); $headers = array('x-amz-pay-Idempotency-Key' => uniqid()); try { $requestPayload = array( 'reportType' => '_GET_FLAT_FILE_OFFAMAZONPAYMENTS_AUTHORIZATION_DATA_', 'startTime' => '20221114T074550Z', 'endTime' => '20221114T074550Z' ); $client = new Amazon\Pay\API\Client($amazonpay_config); $result = $client->createReport($requestPayload); if ($result['status'] === 200) { // success $response = $result['response']; echo $response; } else { // check the error echo 'status=' . $result['status'] . '; response=' . $result['response'] . "\n"; } } catch (\Exception $e) { // handle the exception echo $e . "\n"; } ?>
Amazon Checkout v2报告API - 创建报告计划API
<?php include 'vendor/autoload.php'; $amazonpay_config = array( 'public_key_id' => 'MY_PUBLIC_KEY_ID', 'private_key' => 'keys/private.pem', 'region' => 'US', 'sandbox' => true ); $headers = array('x-amz-pay-Idempotency-Key' => uniqid()); try { $requestPayload = array( 'reportType' => '_GET_FLAT_FILE_OFFAMAZONPAYMENTS_ORDER_REFERENCE_DATA_', 'scheduleFrequency' => 'P1D', 'nextReportCreationTime' => '20221114T074550Z', 'deleteExistingSchedule' => false ); $client = new Amazon\Pay\API\Client($amazonpay_config); $result = $client->createReportSchedule($requestPayload); if ($result['status'] === 200) { // success $response = $result['response']; echo $response; } else { // check the error echo 'status=' . $result['status'] . '; response=' . $result['response'] . "\n"; } } catch (\Exception $e) { // handle the exception echo $e . "\n"; } ?>
Amazon Checkout v2报告API - 取消报告计划API
<?php include 'vendor/autoload.php'; $amazonpay_config = array( 'public_key_id' => 'MY_PUBLIC_KEY_ID', 'private_key' => 'keys/private.pem', 'region' => 'US', 'sandbox' => true ); try { $reportScheduleId = "1234567890"; $client = new Amazon\Pay\API\Client($amazonpay_config); $result = $client->cancelReportSchedule($reportScheduleId); if ($result['status'] === 200) { // success $response = $result['response']; echo $response; } else { // check the error echo 'status=' . $result['status'] . '; response=' . $result['response'] . "\n"; } } catch (\Exception $e) { // handle the exception echo $e . "\n"; } ?>
Amazon Checkout v2报告API - 获取款项API
<?php include 'vendor/autoload.php'; $amazonpay_config = array( 'public_key_id' => 'MY_PUBLIC_KEY_ID', 'private_key' => 'keys/private.pem', 'region' => 'US', 'sandbox' => false ); try { $queryParameters = array( 'startTime' => '20240301T224539Z', 'endTime' => '20240330T230345Z', 'pageSize' => '10', 'nextToken' => '' ); $headers = array('x-amz-pay-idempotency-key' => uniqid()); $client = new Amazon\Pay\API\Client($amazonpay_config); $result = $client->getDisbursements($queryParameters, $headers); print_r($result); } catch (\Exception $e) { // handle the exception echo $e . "\n"; } ?>
Amazon Checkout v2 SPC - finalizeCheckoutSession API
<?php include 'vendor/autoload.php'; require_once 'Amazon/Pay/API/Client.php'; $amazonpay_config = array( 'public_key_id' => 'MY_PUBLIC_KEY_ID', 'private_key' => 'keys/private.pem', 'region' => 'US', 'sandbox' => true, 'algorithm' => 'AMZN-PAY-RSASSA-PSS-V2', ); try{ $payload = array( "shippingAddress" => array( "name" => "Susie Smith", "addressLine1" => "10 Ditka Ave", "addressLine2" => "Suite 2500", "city" => "Chicago", "county" => null, "district" => null, "stateOrRegion" => "IL", "postalCode" => "60602", "countryCode" => "US", "phoneNumber" => "800-000-0000" ), "billingAddress" => null, "chargeAmount" => array( "amount" => "10", "currencyCode" => "USD" ), "totalOrderAmount" => array( "amount" => "10", "currencyCode" => "USD" ), "paymentIntent" => "Confirm", "canHandlePendingAuthorization" => "false" ); $headers = array('x-amz-pay-Idempotency-Key' => uniqid()); $client = new Amazon\Pay\API\Client($amazonpay_config); $checkoutSessionId = "your-checkout-session-id"; $result = $client->finalizeCheckoutSession($checkoutSessionId,$payload, $headers); if ($result['status'] === 200) { // success $response = $result['response']; echo $response; } else { // check the error echo 'status=' . $result['status'] . '; response=' . $result['response'] . "\n"; } } catch (\Exception $e) { // handle the exception echo $e . "\n"; } ?>
账户管理API示例代码
有关账户管理API的更多详细信息,请参阅此集成指南。
Amazon Checkout v2账户管理API - 创建商户账户API
<?php include 'vendor/autoload.php'; require_once 'Amazon/Pay/API/Client.php'; $amazonpay_config = array( 'public_key_id' => 'YOUR_PUBLIC_KEY_ID', 'private_key' => 'keys/private.pem', 'region' => 'JP', 'algorithm' => 'AMZN-PAY-RSASSA-PSS-V2' ); try { $payload = array( "uniqueReferenceId" => "Unique_Reference_Id", // Mandatory "ledgerCurrency" => "JPY", "businessInfo" => array( "email" => "abhi@abc.com", "businessType" => "CORPORATE", "businessLegalName" => "密林コーヒー", "businessCategory" => "Beauty", "businessAddress" => array( "addressLine1" => "扇町4丁目5-1", "addressLine2" => "フルフィルメントセンタービル", "city" => "小田原市", "stateOrRegion" => "神奈川県", "postalCode" => "250-0001", "countryCode" => "JP", "phoneNumber" => array( "countryCode" => "81", "number" => "2062062061" ) ), "businessDisplayName" => "Abhi's Cafe", "annualSalesVolume" => array( "amount" => "100000", "currencyCode" => "JPY" ), "countryOfEstablishment" => "JP", "customerSupportInformation" => array( "customerSupportEmail" => "test.merchant_abhi@abc.com", "customerSupportPhoneNumber" => array( "countryCode" => "1", "number" => "1234567", "extension" => "123" ) ) ), "beneficiaryOwners" => [array( "personFullName" => "Abhishek Kumar", "residentialAddress" => array( "addressLine1" => "扇町4丁目5-1", "addressLine2" => "フルフィルメントセンタービル", "city" => "小田原市", "stateOrRegion" => "神奈川県", "postalCode" => "250-0001", "countryCode" => "JP", "phoneNumber" => array( "countryCode" => "81", "number" => "2062062061" ) ) )], "primaryContactPerson" => array( "personFullName" => "Abhishek Kumar" ), "integrationInfo" => array( "ipnEndpointUrls" => array( "https://yourdomainname.com/ipnendpoint1", "https://yourdomainname.com/ipnendpoint2" ) ), "stores" => array( array( "domainUrls" => array( "https://yourdomainname.com" ), "storeName" => "Rufus's Cafe", "privacyPolicyUrl" => "https://yourdomainname.com/privacy", "storeStatus" => array( "state" => "ACTIVE", "reasonCode" => null ) ) ), "merchantStatus" => array( "statusProvider" => "Ayden", "state" => "ACTIVE", "reasonCode" => null ) ); $client = new Amazon\Pay\API\Client($amazonpay_config); $result = $client->createMerchantAccount($payload, $headers); print_r($result); if ($result['status'] === 201) { // success $response = $result['response']; print_r($response); } else { // check the error echo 'status=' . $result['status'] . '; response=' . $result['response'] . "\n"; } } catch (\Exception $e) { // handle the exception echo $e . "\n"; } ?>
Amazon Checkout v2账户管理API - 更新商户账户API
<?php include 'vendor/autoload.php'; require_once 'Amazon/Pay/API/Client.php'; $amazonpay_config = array( 'public_key_id' => 'YOUR_PUBLIC_KEY_ID', 'private_key' => 'keys/private.pem', 'region' => 'JP', 'algorithm' => 'AMZN-PAY-RSASSA-PSS-V2' ); try { $payload = array( "businessInfo" => array( "email" => "abhi_updated@abc.com", "businessType" => "CORPORATE", "businessLegalName" => "密林コーヒー", "businessCategory" => "Beauty", "businessAddress" => array( "addressLine1" => "扇町4丁目5-1", "addressLine2" => "フルフィルメントセンタービル", "city" => "小田原市", "stateOrRegion" => "神奈川県", "postalCode" => "250-0025", "countryCode" => "JP", "phoneNumber" => array( "countryCode" => "81", "number" => "2062062065" ) ), "businessDisplayName" => "Abhi's Golden Cafe", "annualSalesVolume" => array( "amount" => "500000", "currencyCode" => "JPY" ), "countryOfEstablishment" => "JP", "customerSupportInformation" => array( "customerSupportEmail" => "test.merchant_abhi@abc.com", "customerSupportPhoneNumber" => array( "countryCode" => "1", "number" => "9999999", "extension" => "123" ) ) ) ); $headers = array('x-amz-pay-authtoken' => 'AUTH_TOKEN'); $client = new Amazon\Pay\API\Client($amazonpay_config); $merchantAccountId = "YOUR_MERCHANT_ID"; $result = $client->updateMerchantAccount($merchantAccountId, $payload, $headers); if ($result['status'] === 200) { // success $response = $result['response']; } else { // check the error echo 'status=' . $result['status'] . '; response=' . $result['response'] . "\n"; } } catch (\Exception $e) { // handle the exception echo $e . "\n"; } ?>
Amazon Checkout v2账户管理API - 声明商户账户API
<?php include 'vendor/autoload.php'; require_once 'Amazon/Pay/API/Client.php'; $amazonpay_config = array( 'public_key_id' => 'YOUR_PUBLIC_KEY_ID', 'private_key' => 'keys/private.pem', 'region' => 'JP', 'algorithm' => 'AMZN-PAY-RSASSA-PSS-V2' ); try { $payload = array( "uniqueReferenceId" => "Unique_Reference_Id" // Mandatory ); $headers = array('x-amz-pay-Idempotency-Key' => uniqid()); $client = new Amazon\Pay\API\Client($amazonpay_config); $merchantAccountId = "YOUR_MERCHANT_ID"; $result = $client->claimMerchantAccount($merchantAccountId, $payload, $headers = null); if ($result['status'] === 303 || $result['status'] === 200) { // success $response = $result['response']; } else { // check the error echo 'status=' . $result['status'] . '; response=' . $result['response'] . "\n"; } } catch (\Exception $e) { // handle the exception echo $e . "\n"; } ?>