Skip to content

Commit

Permalink
Amazon Pay API SDK PHP 2.6.6
Browse files Browse the repository at this point in the history
  • Loading branch information
Abhishek Kumar committed Jul 31, 2024
1 parent 77ef94b commit 72fd366
Show file tree
Hide file tree
Showing 7 changed files with 354 additions and 39 deletions.
39 changes: 39 additions & 0 deletions Amazon/Pay/API/AccountManagementClientInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

namespace Amazon\Pay\API;

/* Interface class to showcase the public API methods for Amazon Pay */

interface AccountManagementClientInterface
{
// ----------------------------------- Account Management APIs-----------------------------------

/* Amazon Checkout v2 - Create Merchant Account
*
* Provide merchant info through this API to create loginable account for your merchant partners. Client should expect either a success message or a detailed error message based on data validation and fulfillment.
*
* @param payload - [String in JSON format] or [array]
* @param headers - [array] - requires x-amz-pay-Idempotency-Key header
*/
public function createMerchantAccount($payload, $headers);

/* Amazon Checkout v2 - Update Amazon Pay Merchant Account
*
* Updates a merchant account and store for the given Amazon merchantAccountId. Partners are only able to update fields which do not change the legal business entity itself.
*
* @param merchantAccountId - [String] - Merchant Account ID
* @param payload - [String in JSON format] or [array]
* @param headers - [array] - requires x-amz-pay-authToken header
*/
public function updateMerchantAccount($merchantAccountId, $payload, $headers);

/* Amazon Checkout v2 - Claim Amazon Pay Merchant Account
*
* Initiates the merchant account claim process. Clients should expect a redirection response or a detailed error message based on data validation and fulfillment.
*
* @param merchantAccountId - [String] - Merchant Account ID
* @param payload - [String in JSON format] or [array]
* @optional headers - [indexed array of string key-value pairs]
*/
public function claimMerchantAccount($merchantAccountId, $payload, $headers = null);
}
22 changes: 20 additions & 2 deletions Amazon/Pay/API/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@
require_once 'ReportingClientInterface.php';
require_once 'HttpCurl.php';

class Client implements ClientInterface, ReportingClientInterface, MerchantOnboardingClientInterface
class Client implements ClientInterface, ReportingClientInterface, MerchantOnboardingClientInterface, AccountManagementClientInterface
{
const SDK_VERSION = '2.6.5';
const SDK_VERSION = '2.6.6';
const SDK_LANGUAGE = 'PHP';
const HASH_ALGORITHM = 'sha256';
const API_VERSION = 'v2';
const ACCOUNT_MANAGEMENT = '/merchantAccounts';
const CLAIM = '/claim';

private $config = array();

Expand Down Expand Up @@ -765,4 +766,21 @@ public function deleteAmazonPayAccount($merchantAccountId, $headers = null)
{
return $this->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);
}
}
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
289 changes: 289 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,11 @@ Please contact your Amazon Pay Account Manager before using the In-Store API cal
* **updateAmazonPayAccount**($merchantAccountId, $payload, $headers = null) &#8594; PATCH to "$version/merchantAccounts/$merchantAccountId"
* **deleteAmazonPayAccount**($merchantAccountId, $headers = null) &#8594; DELETE to "$version/merchantAccounts/$merchantAccountId"

### Amazon Checkout v2 Account Management APIs
* **createMerchantAccount**($payload, $headers) &#8594; POST to "$version/merchantAccounts"
* **updateMerchantAccount**($merchantAccountId, $payload, $headers) &#8594; PATCH to "$version/merchantAccounts/$merchantAccountId"
* **claimMerchantAccount**($merchantAccountId, $payload, $headers) &#8594; POST to "$version/merchantAccounts/$merchantAccountId/claim"

# Using Convenience Functions

Four quick steps are needed to make an API call:
Expand Down Expand Up @@ -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
<?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" => "[email protected]",
"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" => "[email protected]",
"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
<?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" => "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
<?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) {
// 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";
}
?>
```
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Loading

0 comments on commit 72fd366

Please sign in to comment.