diff --git a/Amazon/Pay/API/AccountManagementClientInterface.php b/Amazon/Pay/API/AccountManagementClientInterface.php new file mode 100644 index 0000000..a3f54b0 --- /dev/null +++ b/Amazon/Pay/API/AccountManagementClientInterface.php @@ -0,0 +1,39 @@ +apiCall('DELETE', self::API_VERSION . self::ACCOUNT_MANAGEMENT . '/' . $merchantAccountId, null, $headers); } + + // ----------------------------------- Account Management APIs ----------------------------------- + + public function createMerchantAccount($payload, $headers) + { + return $this->apiCall('POST', self::API_VERSION . self::ACCOUNT_MANAGEMENT, $payload, $headers); + } + + public function updateMerchantAccount($merchantAccountId, $payload, $headers) + { + return $this->apiCall('PATCH', self::API_VERSION . self::ACCOUNT_MANAGEMENT . '/' . $merchantAccountId, $payload, $headers); + } + + public function claimMerchantAccount($merchantAccountId, $payload, $headers = null) + { + return $this->apiCall('POST', self::API_VERSION . self::ACCOUNT_MANAGEMENT . '/' . $merchantAccountId . self::CLAIM, $payload, $headers); + } } diff --git a/CHANGES.md b/CHANGES.md index 155cfa6..3d3592f 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,3 +1,6 @@ +### Version 2.6.6 - July 2024 +* Introducing new Account Management APIs that allow partners to programmatically onboard merchants onto the Amazon Pay. + ### Version 2.6.5 - March 2024 * Avoid calling the php_uname function if it's disabled in the php.ini configuration diff --git a/README.md b/README.md index 8fdc531..edc6ef3 100644 --- a/README.md +++ b/README.md @@ -172,6 +172,11 @@ Please contact your Amazon Pay Account Manager before using the In-Store API cal * **updateAmazonPayAccount**($merchantAccountId, $payload, $headers = null) → PATCH to "$version/merchantAccounts/$merchantAccountId" * **deleteAmazonPayAccount**($merchantAccountId, $headers = null) → DELETE to "$version/merchantAccounts/$merchantAccountId" +### Amazon Checkout v2 Account Management APIs +* **createMerchantAccount**($payload, $headers) → POST to "$version/merchantAccounts" +* **updateMerchantAccount**($merchantAccountId, $payload, $headers) → PATCH to "$version/merchantAccounts/$merchantAccountId" +* **claimMerchantAccount**($merchantAccountId, $payload, $headers) → POST to "$version/merchantAccounts/$merchantAccountId/claim" + # Using Convenience Functions Four quick steps are needed to make an API call: @@ -1441,4 +1446,288 @@ if ($result['status'] === 200) { echo $e . "\n"; } ?> +``` +# Sample codes for Account Management APIs +For more details related to Account Management APIs, please refer to this [Integration Guide](https://developer.amazon.com/docs/amazon-pay-registration/jp-merchant-onboarding-and-account-management-APIs.html). + +## Amazon Checkout v2 Account Management APIs - createMerchantAccount API + +```php + '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" + ) + ) + ), // Mandatory + "beneficiaryOwners" => array( + array( + "personId" => "AO1", + "personFullName" => "Abhishek Kumar", + "residentialAddress" => array( + "addressLine1" => "扇町4丁目5-1", + "addressLine2" => "フルフィルメントセンタービル", + "city" => "小田原市", + "stateOrRegion" => "神奈川県", + "postalCode" => "250-0001", + "countryCode" => "JP", + "phoneNumber" => array( + "countryCode" => "81", + "number" => "2062062061" + ) + ) + ), + array( + "personId" => "AO2", + "personFullName" => "Rufus1 Rufus1", + "residentialAddress" => array( + "addressLine1" => "扇町4丁目5-1", + "addressLine2" => "フルフィルメントセンタービル", + "city" => "小田原市", + "stateOrRegion" => "神奈川県", + "postalCode" => "250-0001", + "countryCode" => "JP", + "phoneNumber" => array( + "countryCode" => "81", + "number" => "2062062061" + ) + ) + ) + ), // Mandatory + "primaryContactPerson" => array( + "personFullName" => "Abhishek Kumar" + ), // Optional + "integrationInfo" => array( + "ipnEndpointUrls" => array( + "https://yourdomainname.com/ipnendpoint1", + "https://yourdomainname.com/ipnendpoint2" + ) + ), // Optionals + "stores" => array( + array( + "domainUrls" => array( + "http://www.yourdomainname.com" + ), + "storeName" => "Rufus's Cafe", + "privacyPolicyUrl" => "http://www.yourdomainname.com/privacy", + "storeStatus" => array( + "state" => "Active", + "reasonCode" => null + ) + ) + ), // Mandatory + "merchantStatus" => array( + "statusProvider" => "Ayden", + "state" => "ACTIVE", + "reasonCode" => null + ) // Mandatory + ); + + $headers = array('x-amz-pay-Idempotency-Key' => uniqid()); + $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 Account Management APIs - updateMerchantAccount API + +```php + 'YOUR_PUBLIC_KEY_ID', + 'private_key' => 'keys/private.pem', + 'region' => 'JP', + 'algorithm' => 'AMZN-PAY-RSASSA-PSS-V2' + ); + + try { + + $payload = array( + "uniqueReferenceId" => "String", // Mandatory + "ownerAccountId" => "String", // Optional + "businessInfo" => array( + "email" => "String", // Mandatory + "businessCategory" => "ENUM", // Mandatory + "countryOfEstablishment" => "JP", // Mandatory (JP for Japan) + "businessType" => "ENUM", // Mandatory (e.g., Corporate) + "businessLegalName" => "String", // Mandatory + "businessAddress" => array( + "addressLine1" => "String", // Mandatory + "addressLine2" => "String", // Optional + "city" => "String", // Optional + "stateOrRegion" => "String", // Optional + "postalCode" => "String", // Mandatory + "countryCode" => "String" // Mandatory + ), + "businessDisplayName" => "String", // Mandatory + "customerSupportInformation" => array( + "customerSupportEmail" => "String", // Optional + "customerSupportPhoneNumber" => array( + "countryCode" => "String", // Mandatory + "number" => "String", // Mandatory + "extension" => "String" // Optional + ) + ), + "annualSalesVolume" => array( + "amount" => "String", // Mandatory + "currencyCode" => "String" // Optional (ISO 4217) + ) // Optional + ), + "primaryContactPerson" => array( + "personFullName" => "String", // Mandatory + "residentialAddress" => array( + "addressLine1" => "String", // Mandatory + "addressLine2" => "String", // Optional + "city" => "String", // Optional + "stateOrRegion" => "String", // Optional + "postalCode" => "String", // Mandatory + "countryCode" => "String" // Mandatory + ) // Optional + ), + "beneficiaryOwners" => array( + array( + "personFullName" => "String", // Mandatory + "residentialAddress" => array( + "addressLine1" => "String", // Mandatory + "addressLine2" => "String", // Optional + "city" => "String", // Optional + "stateOrRegion" => "String", // Optional + "postalCode" => "String", // Mandatory + "countryCode" => "String" // Mandatory + ) // Optional + ) + ), // Mandatory + "defaultStore" => array( + "domainUrls" => array("String"), // Mandatory + "storeName" => "String", // Optional + "privacyPolicyUrl" => "String", // Optional + "storeStatus" => array( + "state" => "ENUM", // Mandatory + "reasonCode" => "ENUM" // Optional + ) // Optional + ), + "integrationInfo" => array( + "ipnEndpointUrl" => array("String") // Optional + ), + "merchantStatus" => array( + "statusProvider" => "String", // Optional (Mandatory if state is Active) + "state" => "ENUM", // Mandatory + "reasonCode" => "ENUM" // Optional + ) + ); + + $headers = array('x-amz-pay-authtoken' => 'other_merchant_super_secret_token'); // Mandatory + $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 Account Management APIs - claimMerchantAccount API + +```php + '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) { + // 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"; + } +?> ``` \ No newline at end of file diff --git a/composer.json b/composer.json index 88cfc49..5fb9a79 100644 --- a/composer.json +++ b/composer.json @@ -2,7 +2,7 @@ "name": "amzn/amazon-pay-api-sdk-php", "type": "library", "description": "Amazon Pay API SDK (PHP)", - "version": "2.6.5", + "version": "2.6.6", "keywords": [ "amazon", "pay", diff --git a/tests/unit/unit_test_key_private.txt b/tests/unit/unit_test_key_private.txt index bb0561e..d9faca5 100644 --- a/tests/unit/unit_test_key_private.txt +++ b/tests/unit/unit_test_key_private.txt @@ -1,27 +1 @@ ------BEGIN RSA PRIVATE KEY----- -MIIEowIBAAKCAQEA6Eqj050ePXhA39d4FyvSQyIbW9frefsjw9JSPIRHX4XimpAO -gJ75BmG/wptqXOG79xDyWOXmHHz5alRjvoQAlI7HOdnScWxHO+9esm1koJyvug23 -Pa5KN8j7BYRpFOuYhFS8hxUEsmMYSw7iIsckbqBB7VzxnGfP10kNcAhJ+GSbHN74 -CsqJJkX+66m85Mrb/13QxZVbIsZLwfQ/S12lStvI1rjtyXBEmfEWNOZLQdPdM2QB -kCm+vp9QjsD2zpINCCazp+DibqjcCtSGN2mSiraFSBKdg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5Ey/zoL1lm4S3R7ndW0kNMHAVdgJITJXvb -O05ORQKBgEGPnMKv7dJA10Un77GMH7+6/ujWfL4JRj+Aa6l0RCnc05rECtkF5V27 -gzjqRXZYIRczgyXa1MpNeZgE0C7MpXSbzTR4L8E9bMH2b+R4EjX8hoY32BReW0uA -b4k6oZiNnDl1XZgwczfC1sTF/QsOJPe8i70Vzh/ZNG7DGw2dePLA ------END RSA PRIVATE KEY----- +Enter your private key. \ No newline at end of file diff --git a/tests/unit/unit_test_key_public.txt b/tests/unit/unit_test_key_public.txt index 796c694..b1b5d15 100644 --- a/tests/unit/unit_test_key_public.txt +++ b/tests/unit/unit_test_key_public.txt @@ -1,9 +1 @@ ------BEGIN PUBLIC KEY----- -MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA6Eqj050ePXhA39d4FyvS -QyIbW9frefsjw9JSPIRHX4XimpAOgJ75BmG/wptqXOG79xDyWOXmHHz5alRjvoQA -lI7HOdnScWxHO+9esm1koJyvug23Pa5KN8j7BYRpFOuYhFS8hxUEsmMYSw7iIsck -bqBB7VzxnGfP10kNcAhJ+GSbHN74CsqJJkX+66m85Mrb/13QxZVbIsZLwfQ/S12l -StvI1rjtyXBEmfEWNOZLQdPdM2QBkCm+vp9QjsD2zpINCCazp+DibqjcCtSGN2mS -iraFSBKdg1E55K11E56pF55BsZk5lo8/aGAMEYzJB4XYwaMV21Fadg8sM0NRlBFl -uwIDAQAB ------END PUBLIC KEY----- +Enter your public key. \ No newline at end of file