Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release/2.5.1 #215

Open
wants to merge 21 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
1d0bbf8
Merge branch 'main' into tweak/plugin-header-updates
dpanta94 Mar 27, 2023
0d3901d
added method to provide extra headers
dpanta94 Mar 28, 2023
8cb2cf2
updates V2 request headers
dpanta94 Mar 28, 2023
d067d2a
amended code based on CR
dpanta94 Mar 28, 2023
c08883f
Merge branch 'main' into tweak/plugin-header-updates
dpanta94 Apr 26, 2023
353c7e4
Fixed logging of headers to aid QA
dpanta94 Apr 26, 2023
5134d49
Update amazon pay SDK
dpanta94 Jul 7, 2023
22cb35a
do not estimated order amount if currency not supported
alexiglesias31 Sep 18, 2023
4b12d68
Add unit tests
alexiglesias31 Sep 18, 2023
93dfbcf
amends from CR
alexiglesias31 Sep 20, 2023
3f1e12d
update tests
alexiglesias31 Sep 20, 2023
617866b
do not set the parameter if EOA is empty
alexiglesias31 Sep 20, 2023
6a50029
update tests
alexiglesias31 Sep 20, 2023
01c4a75
Extendable multicurrency compatibility
dpanta94 Sep 25, 2023
6452d6e
revert accidental code push
dpanta94 Sep 25, 2023
2a60c42
prevent set eoa on blocks
alexiglesias31 Sep 27, 2023
f23a8ef
Merge branch 'fix/issue-270-estimated-order-amount-multicurrency' int…
alexiglesias31 Oct 9, 2023
28ba70d
Merge remote-tracking branch 'origin/feature/imporve-mutlicurrency-co…
alexiglesias31 Oct 9, 2023
0995e70
Merge branch 'tweak/plugin-header-updates' into release/2.6.0
alexiglesias31 Oct 9, 2023
c2557a4
bump versions to 2.5.1
alexiglesias31 Oct 9, 2023
6a85006
Revert "Merge branch 'fix/issue-270-estimated-order-amount-multicurre…
alexiglesias31 Oct 10, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
*** Amazon Pay Changelog ***

= 2.5.1 - 2023-10-09 =

* Add - Improve multi-currency compatibility support.
* Fix - Issue with estimatedOrderAmount and multi-currency.
* Update - Amazon Pay SDK.

= 2.5.0 - 2023-07-20 =

* Add - Plugin review Prompt.
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"yoast/phpunit-polyfills": "^1.0"
},
"require": {
"amzn/amazon-pay-api-sdk-php": "2.5.2",
"amzn/amazon-pay-api-sdk-php": "2.6.2",
"php": "7.*"
}
}
14 changes: 7 additions & 7 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions includes/class-wc-amazon-payments-advanced-api-abstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -531,4 +531,18 @@ public static function validate_api_keys() {
return false;
}

/**
* Returns extra headers to be added to requests against Amazon Pay API.
*
* @return array
*/
protected static function get_amazon_pay_platform_headers() {
$version_suffix = wc_apa()->get_gateway() instanceof WC_Gateway_Amazon_Payments_Advanced_Legacy ? '-legacy' : '';

return array(
'x-amz-pay-platform-version' => WC()->version,
'x-amz-pay-integrator-version' => wc_apa()->version . $version_suffix,
'x-amz-pay-integrator-id' => static::AMAZON_PAY_FOR_WOOCOMMERCE_SP_ID,
);
}
}
178 changes: 141 additions & 37 deletions includes/class-wc-amazon-payments-advanced-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,20 @@ public static function validate_api_keys() {
$client = self::get_client();
$payload = self::create_checkout_session_params();

$headers = array( 'x-amz-pay-Idempotency-Key' => uniqid() );
$result = $client->createCheckoutSession( $payload, $headers );
$headers = array_merge(
array( 'x-amz-pay-Idempotency-Key' => uniqid() ),
self::get_amazon_pay_platform_headers()
);

wc_apa()->log(
'Validating API keys.',
array(
'payload' => $payload,
'headers' => $headers,
)
);

$result = $client->createCheckoutSession( $payload, $headers );
if ( ! isset( $result['status'] ) || 201 !== $result['status'] ) {
throw new Exception( __( 'Error: API is not responding.', 'woocommerce-gateway-amazon-payments-advanced' ) );
}
Expand All @@ -99,7 +111,17 @@ public static function validate_api_keys() {
* @return array
*/
public static function trigger_alexa_notifications( $payload ) {
return self::get_client()->deliveryTrackers( $payload );
$headers = self::get_amazon_pay_platform_headers();

wc_apa()->log(
'Enabling Alexa notifications.',
array(
'payload' => $payload,
'headers' => $headers,
)
);

return self::get_client()->deliveryTrackers( $payload, $headers );
}

/**
Expand Down Expand Up @@ -486,7 +508,17 @@ public static function get_create_checkout_classic_session_config( $payload ) {
*/
public static function get_checkout_session_data( $checkout_session_id ) {
$client = self::get_client();
$result = $client->getCheckoutSession( $checkout_session_id );

$headers = self::get_amazon_pay_platform_headers();

wc_apa()->log(
sprintf( 'Retrieving session data for session %s', $checkout_session_id ),
array(
'headers' => $headers,
)
);

$result = $client->getCheckoutSession( $checkout_session_id, $headers );
if ( ! isset( $result['status'] ) || 200 !== $result['status'] ) {
return new WP_Error( $result['status'], __( 'Error while getting checkout session.', 'woocommerce-gateway-amazon-payments-advanced' ) );
}
Expand Down Expand Up @@ -533,7 +565,10 @@ protected static function normalize_address( $address ) {
public static function update_checkout_session_data( $checkout_session_id, $data = array() ) {
$client = self::get_client();

$headers = self::get_extra_headers( __FUNCTION__ );
$headers = array_merge(
self::get_extra_headers( __FUNCTION__ ),
self::get_amazon_pay_platform_headers()
);

wc_apa()->log(
sprintf( 'Checkout Session ID %s', $checkout_session_id ),
Expand Down Expand Up @@ -565,9 +600,18 @@ public static function update_checkout_session_data( $checkout_session_id, $data
* @return object|WP_Error API Response, or WP_Error.
*/
public static function complete_checkout_session( $checkout_session_id, $data = array() ) {
$client = self::get_client();
wc_apa()->log( sprintf( 'Checkout Session ID %s', $checkout_session_id ), $data );
$result = $client->completeCheckoutSession( $checkout_session_id, $data );
$client = self::get_client();
$headers = self::get_amazon_pay_platform_headers();

wc_apa()->log(
sprintf( 'Completing Checkout Session ID %s', $checkout_session_id ),
array(
'data' => $data,
'headers' => $headers,
)
);

$result = $client->completeCheckoutSession( $checkout_session_id, $data, $headers );

$response = json_decode( $result['response'] );

Expand Down Expand Up @@ -619,7 +663,17 @@ public static function get_languages_per_region() {
*/
public static function get_charge_permission( $charge_permission_id ) {
$client = self::get_client();
$result = $client->getChargePermission( $charge_permission_id );

$headers = self::get_amazon_pay_platform_headers();

wc_apa()->log(
sprintf( 'Retrieving Charge Permission ID %s', $charge_permission_id ),
array(
'headers' => $headers,
)
);

$result = $client->getChargePermission( $charge_permission_id, $headers );

$response = json_decode( $result['response'] );

Expand All @@ -638,7 +692,17 @@ public static function get_charge_permission( $charge_permission_id ) {
*/
public static function get_charge( $charge_id ) {
$client = self::get_client();
$result = $client->getCharge( $charge_id );

$headers = self::get_amazon_pay_platform_headers();

wc_apa()->log(
sprintf( 'Retrieving Charge ID %s', $charge_id ),
array(
'headers' => $headers,
)
);

$result = $client->getCharge( $charge_id, $headers );

$response = json_decode( $result['response'] );

Expand All @@ -657,7 +721,17 @@ public static function get_charge( $charge_id ) {
*/
public static function get_refund( $refund_id ) {
$client = self::get_client();
$result = $client->getRefund( $refund_id );

$headers = self::get_amazon_pay_platform_headers();

wc_apa()->log(
sprintf( 'Retrieving Refund ID %s', $refund_id ),
array(
'headers' => $headers,
)
);

$result = $client->getRefund( $refund_id, $headers );

$response = json_decode( $result['response'] );

Expand Down Expand Up @@ -706,7 +780,10 @@ public static function capture_charge( $charge_id, $data = array() ) {
// TODO: Test with lower amount of captured than charge (multiple charges per capture).
}

$headers = self::get_extra_headers( __FUNCTION__ );
$headers = array_merge(
self::get_extra_headers( __FUNCTION__ ),
self::get_amazon_pay_platform_headers()
);

wc_apa()->log(
sprintf( 'Charge ID %s.', $charge_id ),
Expand All @@ -716,15 +793,17 @@ public static function capture_charge( $charge_id, $data = array() ) {
)
);

$headers = array_merge(
$headers,
array(
'x-amz-pay-idempotency-key' => self::generate_uuid(),
)
);

$result = $client->captureCharge(
$charge_id,
$data,
array_merge(
$headers,
array(
'x-amz-pay-idempotency-key' => self::generate_uuid(),
)
)
$headers
);

$response = json_decode( $result['response'] );
Expand Down Expand Up @@ -763,7 +842,10 @@ public static function refund_charge( $charge_id, $amount = null, $data = array(
$data['refundAmount']['amount'] = $amount;
}

$headers = self::get_extra_headers( __FUNCTION__ );
$headers = array_merge(
self::get_extra_headers( __FUNCTION__ ),
self::get_amazon_pay_platform_headers()
);

wc_apa()->log(
sprintf( 'Charge ID %s.', $charge_id ),
Expand All @@ -773,14 +855,16 @@ public static function refund_charge( $charge_id, $amount = null, $data = array(
)
);

$headers = array_merge(
$headers,
array(
'x-amz-pay-idempotency-key' => self::generate_uuid(),
)
);

$result = $client->createRefund(
$data,
array_merge(
$headers,
array(
'x-amz-pay-idempotency-key' => self::generate_uuid(),
)
)
$headers
);

$response = json_decode( $result['response'] );
Expand All @@ -804,15 +888,27 @@ public static function refund_charge( $charge_id, $amount = null, $data = array(
*/
public static function cancel_charge( $charge_id, $reason = 'Order Cancelled' ) {
$client = self::get_client();
wc_apa()->log( sprintf( 'Charge ID %s.', $charge_id ) );

$result = $client->cancelCharge(
$charge_id,
$data = array(
'cancellationReason' => $reason, // TODO: Make dynamic.
);

$headers = self::get_amazon_pay_platform_headers();

wc_apa()->log(
sprintf( 'Charge ID %s.', $charge_id ),
array(
'cancellationReason' => $reason, // TODO: Make dynamic.
'data' => $data,
'headers' => $headers,
)
);

$result = $client->cancelCharge(
$charge_id,
$data,
$headers
);

$response = json_decode( $result['response'] );

if ( ! isset( $result['status'] ) || ! in_array( $result['status'], array( 200, 201 ), true ) ) {
Expand Down Expand Up @@ -927,7 +1023,10 @@ public static function create_charge( $charge_permission_id, $data ) {
$data['chargeAmount'] = (array) $charge_permission->limits->amountBalance; // phpcs:ignore WordPress.NamingConventions
}

$headers = self::get_extra_headers( __FUNCTION__ );
$headers = array_merge(
self::get_extra_headers( __FUNCTION__ ),
self::get_amazon_pay_platform_headers()
);

wc_apa()->log(
sprintf( 'Charge Permission ID %s.', $charge_permission_id ),
Expand All @@ -937,14 +1036,16 @@ public static function create_charge( $charge_permission_id, $data ) {
)
);

$headers = array_merge(
$headers,
array(
'x-amz-pay-idempotency-key' => self::generate_uuid(),
)
);

$result = $client->createCharge(
$data,
array_merge(
$headers,
array(
'x-amz-pay-idempotency-key' => self::generate_uuid(),
)
)
$headers
);

$response = json_decode( $result['response'] );
Expand All @@ -969,7 +1070,10 @@ public static function create_charge( $charge_permission_id, $data ) {
public static function close_charge_permission( $charge_permission_id, $reason = 'Subscription Cancelled' ) {
$client = self::get_client();

$headers = self::get_extra_headers( __FUNCTION__ );
$headers = array_merge(
self::get_extra_headers( __FUNCTION__ ),
self::get_amazon_pay_platform_headers()
);

wc_apa()->log( sprintf( 'Charge Permission ID %s.', $charge_permission_id ), array( 'headers' => $headers ) );

Expand Down
Loading