From 5d5c6a49cc98b50b92bc48e64eaef67ec349f7ff Mon Sep 17 00:00:00 2001 From: awaldia Date: Fri, 17 Mar 2023 16:17:57 +0530 Subject: [PATCH] Amazon Pay API SDK PHP 2.6.0 --- Amazon/Pay/API/Client.php | 54 +++++- Amazon/Pay/API/ClientInterface.php | 85 +++++++++ CHANGES.md | 3 + README.md | 291 +++++++++++++++++++++++++++++ composer.json | 2 +- 5 files changed, 433 insertions(+), 2 deletions(-) diff --git a/Amazon/Pay/API/Client.php b/Amazon/Pay/API/Client.php index 1eba0ac..bb501f1 100644 --- a/Amazon/Pay/API/Client.php +++ b/Amazon/Pay/API/Client.php @@ -10,7 +10,7 @@ class Client implements ClientInterface { - const SDK_VERSION = '2.5.2'; + const SDK_VERSION = '2.6.0'; const HASH_ALGORITHM = 'sha256'; const API_VERSION = 'v2'; @@ -645,4 +645,56 @@ public function getRefund($refundId, $headers = null) return $this->apiCall('GET', self::API_VERSION . '/refunds/' . $refundId, null, $headers); } + // ----------------------------------- CV2 REPORTING APIS ----------------------------------- + + + public function getReports($queryParameters = null, $headers = null) + { + return $this->apiCall('GET', self::API_VERSION . '/reports', null, $headers, $queryParameters); + } + + + public function getReportById($reportId, $headers = null) + { + return $this->apiCall('GET', self::API_VERSION . '/reports/' . $reportId, null, $headers); + } + + + public function getReportDocument($reportDocumentId, $headers = null) + { + return $this->apiCall('GET', self::API_VERSION . '/report-documents/' . $reportDocumentId, null, $headers); + } + + + public function getReportSchedules($reportTypes = null, $headers = null) + { + $queryParameters = array('reportTypes' => $reportTypes); + return $this->apiCall('GET', self::API_VERSION . '/report-schedules', null, $headers, $queryParameters); + } + + + public function getReportScheduleById($reportScheduleId, $headers = null) + { + return $this->apiCall('GET', self::API_VERSION . '/report-schedules/' . $reportScheduleId, null, $headers); + } + + + public function createReport($requestPayload, $headers = null) + { + return $this->apiCall('POST', self::API_VERSION . '/reports' , $requestPayload, $headers); + } + + + public function createReportSchedule($requestPayload, $headers = null) + { + return $this->apiCall('POST', self::API_VERSION . '/report-schedules' , $requestPayload, $headers); + } + + + public function cancelReportSchedule($reportScheduleId, $headers = null) + { + return $this->apiCall('DELETE', self::API_VERSION . '/report-schedules/' . $reportScheduleId, null, $headers); + } + + } diff --git a/Amazon/Pay/API/ClientInterface.php b/Amazon/Pay/API/ClientInterface.php index 5ad6437..189ec25 100644 --- a/Amazon/Pay/API/ClientInterface.php +++ b/Amazon/Pay/API/ClientInterface.php @@ -258,4 +258,89 @@ public function createSignature($http_request_method, $request_uri, $request_par */ public function apiCall($method, $urlFragment, $payload, $headers = null); + + // ----------------------------------- Reporting v2 APIs ----------------------------------- + + + /* Amazon Checkout v2 Reporting APIs - Get Reports + * + * Returns report details for the reports that match the filters that you specify. + * + * @optional queryParameters - [String in JSON format] or [array] + * @optional headers - [array] - optional x-amz-pay-authtoken + */ + public function getReports($queryParameters = null, $headers = null); + + + /* Amazon Checkout v2 Reporting APIs - Get Report By Id + * + * Returns report details for the given reportId. + * + * @param $reportId [String] + * @optional headers - [array] - optional x-amz-pay-authtoken + */ + public function getReportById($reportId, $headers = null); + + + /* Amazon Checkout v2 Reporting APIs - Get Report Document + * + * Returns the pre-signed S3 URL for the report. The report can be downloaded using this URL. + * + * @param $reportDocumentId [String] + * @optional headers - [array] - optional x-amz-pay-authtoken + */ + public function getReportDocument($reportDocumentId, $headers = null); + + + /* Amazon Checkout v2 Reporting APIs - Get Report Schedules + * + * Returns report schedule details that match the filters criteria specified. + * + * @optional reportTypes - [String] + * @optional headers - [array] - optional x-amz-pay-authtoken + */ + public function getReportSchedules($reportTypes = null, $headers = null); + + + + /* Amazon Checkout v2 Reporting APIs - Get Report Schedules By Id + * + * Returns the report schedule details that match the given ID. + * + * @param $reportScheduleId [String] + * @optional headers - [array] - optional x-amz-pay-authtoken + */ + public function getReportScheduleById($reportScheduleId, $headers = null); + + + /* Amazon Checkout v2 Reporting APIs - Create Report + * + * Submits a request to generate a report based on the reportType and date range specified. + * + * @param $requestPayload [String in JSON format] or [array] + * @optional headers - [array] - optional x-amz-pay-authtoken + */ + public function createReport($requestPayload, $headers); + + + /* Amazon Checkout v2 Reporting APIs - Create Report Schedule + * + * Creates a report schedule for the given reportType. Only one schedule per report type allowed. + * + * @param $requestPayload [String in JSON format] or [array] + * @param headers - [array] - requires x-amz-pay-Idempotency-Key header; optional x-amz-pay-authtoken + */ + public function createReportSchedule($requestPayload, $headers); + + + /* Amazon Checkout v2 Reporting APIs - Cancel Report Schedule + * + * Cancels the report schedule with the given reportScheduleId. + * + * @param $reportScheduleId [String] + * @optional headers - [array] - optional x-amz-pay-authtoken + */ + public function cancelReportSchedule($reportScheduleId, $headers = null); + + } diff --git a/CHANGES.md b/CHANGES.md index 7835f60..07e574f 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,3 +1,6 @@ +### Version 2.6.0 - March 2023 +* Introducing new v2 Reporting APIs. Reports allow you to retrieve consolidated data about Amazon Pay transactions and settlements. In addition to managing and downloading reports using Seller Central, Amazon Pay offers APIs to manage and retrieve your reports. + ### Version 2.5.2 - March 2023 * Added Error Code 408 to API retry logic * Corrected Typos & refactored codes diff --git a/README.md b/README.md index 6c8de29..ed8509a 100644 --- a/README.md +++ b/README.md @@ -632,3 +632,294 @@ Example call to createSignature function with values: $client = new Client($amazonpay_config); $signedInput = $client->createSignature($method, $url, $requestParameters, $pre_signed_headers, $payload, '20180326T203730Z'); ``` + +# Reporting APIs code samples + +## Amazon Checkout v2 Reporting APIs - GetReport API + +```php + 'MY_PUBLIC_KEY_ID', + 'private_key' => 'keys/private.pem', + 'region' => 'US', + 'sandbox' => false + ); + + $requestPayload = array( + 'reportType' => '_GET_FLAT_FILE_OFFAMAZONPAYMENTS_ORDER_REFERENCE_DATA_', + 'processingStatus' => '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 Reporting APIs - GetReportById API + +```php + '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 Reporting APIs - GetReportDocument API + +```php + 'MY_PUBLIC_KEY_ID', + 'private_key' => 'keys/private.pem', + 'region' => 'US', + 'sandbox' => true + ); + + try { + $reportDocumentId = "1234567890"; + $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 Reporting APIs - GetReportSchedules API + +```php + '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 Reporting APIs - GetReportScheduleById API + +```php + '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 Reporting APIs - CreateReport API + +```php + '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 Reporting APIs - CreateReportSchedule API + +```php + '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 Reporting APIs - CancelReportSchedule API + +```php + '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"; + } + ?> +``` \ No newline at end of file diff --git a/composer.json b/composer.json index 6cff707..5ef4a3e 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.5.2", + "version": "2.6.0", "keywords": [ "amazon", "pay",