Skip to content

Commit 3e41c7f

Browse files
authored
Merge pull request #42 from saucal/hotfix/alpha3
Alpha 3
2 parents 3beeefc + 7eda6ff commit 3e41c7f

7 files changed

+335
-135
lines changed

assets/js/amazon-wc-checkout.js

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
var button_settings = {
2222
// set checkout environment
2323
merchantId: amazon_payments_advanced.merchant_id,
24-
ledgerCurrency: 'EUR', // TODO: Implement multicurrency
24+
ledgerCurrency: amazon_payments_advanced.ledger_currency,
2525
sandbox: amazon_payments_advanced.sandbox === '1' ? true : false,
2626
// customize the buyer experience
2727
productType: amazon_payments_advanced.action,
@@ -49,10 +49,12 @@
4949
}
5050

5151
function activateChange( button_id, action ) {
52-
if ( 0 === $( button_id ).length ) {
52+
var $btn = $( button_id );
53+
if ( 0 === $btn.length || $btn.data( 'wc_apa_chage_bind' ) === action ) {
5354
return;
5455
}
55-
$( button_id ).on( 'click', function( e ) {
56+
$btn.data( 'wc_apa_chage_bind', action );
57+
$btn.on( 'click', function( e ) {
5658
e.preventDefault();
5759
} );
5860
amazon.Pay.bindChangeAction( button_id, {
@@ -77,28 +79,34 @@
7779
}
7880

7981
function initAmazonPaymentFields() {
82+
if ( ! isAmazonCheckout() ) {
83+
return;
84+
}
8085
toggleDetailsVisibility( 'woocommerce-billing-fields' );
8186
toggleDetailsVisibility( 'woocommerce-shipping-fields' );
8287
toggleDetailsVisibility( 'woocommerce-additional-fields' );
8388
activateChange( '#payment_method_widget_change', 'changePayment' );
8489
activateChange( '#shipping_address_widget_change', 'changeAddress' );
85-
}
8690

87-
$( 'body' ).on( 'updated_checkout', function() {
88-
initAmazonPaymentFields();
89-
if ( ! isAmazonCheckout() ) {
90-
return;
91-
}
9291
if ( $( '.woocommerce-billing-fields .woocommerce-billing-fields__field-wrapper > *' ).length > 0 ) {
9392
$( '.woocommerce-billing-fields' ).insertBefore( '#payment' );
9493
}
94+
95+
if ( $( '.woocommerce-account-fields' ).length > 0 ) {
96+
$( '.woocommerce-account-fields' ).insertBefore( '#wc-apa-account-fields-anchor' );
97+
}
98+
9599
if ( $( '.woocommerce-shipping-fields .woocommerce-shipping-fields__field-wrapper > *' ).length > 0 ) {
96100
var title = $( '#ship-to-different-address' );
97101
title.find( ':checkbox#ship-to-different-address-checkbox' ).hide();
98102
title.find( 'span' ).text( amazon_payments_advanced.shipping_title );
99103
$( '.woocommerce-shipping-fields' ).insertBefore( '#payment' );
100104
}
101105
$( '.woocommerce-additional-fields' ).insertBefore( '#payment' );
102-
} );
106+
}
107+
108+
initAmazonPaymentFields();
109+
110+
$( 'body' ).on( 'updated_checkout', initAmazonPaymentFields );
103111
} );
104112
} )( jQuery );

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
},
1717
"require-dev": {
1818
"phpunit/phpunit": "5.7.27",
19-
"woocommerce/woocommerce-sniffs": "0.0.8"
19+
"woocommerce/woocommerce-sniffs": "0.1.0"
2020
},
2121
"require": {
2222
"amzn/amazon-pay-api-sdk-php": "^2.2"

0 commit comments

Comments
 (0)