Skip to content

Commit

Permalink
Amazon Pay API SDK PHP 2.6.3
Browse files Browse the repository at this point in the history
  • Loading branch information
Nayan Kumar S committed Sep 7, 2023
1 parent 4583b73 commit ab02d97
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 4 deletions.
9 changes: 8 additions & 1 deletion Amazon/Pay/API/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

class Client implements ClientInterface, ReportingClientInterface
{
const SDK_VERSION = '2.6.2';
const SDK_VERSION = '2.6.3';
const SDK_LANGUAGE = 'PHP';
const HASH_ALGORITHM = 'sha256';
const API_VERSION = 'v2';
Expand Down Expand Up @@ -713,5 +713,12 @@ public function cancelReportSchedule($reportScheduleId, $headers = null)
return $this->apiCall('DELETE', self::API_VERSION . '/report-schedules/' . $reportScheduleId, null, $headers);
}

/*
* FinalizeCheckoutSession API which enables Pay to validate payment critical attributes and also update book-keeping attributes present in merchantMetadata
*/
public function finalizeCheckoutSession($checkoutSessionId, $payload, $headers = null)
{
return $this->apicall('POST', self::API_VERSION . '/checkoutSessions/' . $checkoutSessionId . '/finalize', $payload , $headers);
}

}
13 changes: 12 additions & 1 deletion Amazon/Pay/API/ClientInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -257,5 +257,16 @@ public function createSignature($http_request_method, $request_uri, $request_par
* @optional headers - [indexed array of string key-value pairs]
*/
public function apiCall($method, $urlFragment, $payload, $headers = null);



// ----------------------------------- Single Page Checkout -----------------------------------

/*
*
* FinalizeCheckoutSession API which enables Pay to validate payment critical attributes and also update book-keeping attributes present in merchantMetadata
* @param checkoutSessionId - [String] Checkout Session identifier
* @param $payload [String in JSON format] or [Array]
*/

public function finalizeCheckoutSession($checkoutSessionId, $payload, $headers = null);
}
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
### Version 2.6.3 - September 2023
* Introducing new API called finalizeCheckoutSession which validates critical attributes in merchantMetadata then processes payment. Use this API to process payments for JavaScript-based integrations.
* Corrected README.md file related to finalizeCheckoutSession API.

### Version 2.6.2 - June 2023
* Added optional headers to APIs. These are intended to be used by solution providers to send their platform/plugin id’s and versions.
* Corrected README.md file related to Reporting APIs.
Expand Down
61 changes: 60 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,8 @@ Please contact your Amazon Pay Account Manager before using the In-Store API cal
* **instoreCharge**($payload, $headers = null) → POST to "$version/in-store/charge"
* **instoreRefund**($payload, $headers = null) → POST to "$version/in-store/refund"

### Amazon Checkout v2 SPC
* **finalizeCheckoutSession**($checkoutSessionId, $payload, $headers = null) → POST to "$version/checkoutSessions/$checkoutSessionId/finalize"

# Using Convenience Functions

Expand Down Expand Up @@ -943,4 +945,61 @@ Example call to createSignature function with values:
echo $e . "\n";
}
?>
```
```
## Amazon Checkout v2 SPC - finalizeCheckoutSession API

```php
<?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";
}
?>
```
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.2",
"version": "2.6.3",
"keywords": [
"amazon",
"pay",
Expand Down

0 comments on commit ab02d97

Please sign in to comment.