Skip to content

Commit

Permalink
Apple Pay on PDP causes issue on normal add to cart closes #195
Browse files Browse the repository at this point in the history
  • Loading branch information
roykho committed Mar 21, 2017
1 parent a13d3d9 commit f8f010a
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 15 deletions.
35 changes: 22 additions & 13 deletions assets/js/stripe-apple-pay-single.js
Expand Up @@ -26,16 +26,6 @@ jQuery( function( $ ) {
init: function() {
Stripe.applePay.checkAvailability( function( available ) {
if ( available ) {
$( document.body ).on( 'woocommerce_variation_has_changed', function() {
wc_stripe_apple_pay_single.generate_cart();
})

.on( 'change', '.quantity .qty', function() {
wc_stripe_apple_pay_single.generate_cart();
});

wc_stripe_apple_pay_single.generate_cart();

$( '.apple-pay-button' ).show();
}
});
Expand All @@ -61,9 +51,14 @@ jQuery( function( $ ) {
currencyCode: wc_stripe_apple_pay_single_params.currency_code,
total: {
label: wc_stripe_apple_pay_single_params.label,
amount: wc_stripe_apple_pay_single_params.total
amount: 1,
type: 'pending'
},
lineItems: {
label: 'Sub-Total',
amount: 1,
type: 'pending'
},
lineItems: wc_stripe_apple_pay_single_params.line_items,
requiredBillingContactFields: ['postalAddress'],
requiredShippingContactFields: 'yes' === wc_stripe_apple_pay_single_params.needs_shipping ? ['postalAddress', 'phone', 'email', 'name'] : ['phone', 'email', 'name']
};
Expand Down Expand Up @@ -126,7 +121,7 @@ jQuery( function( $ ) {
});
};

// After the shipping method has been selected
// After the shipping method has been selected.
applePaySession.onshippingmethodselected = function( event ) {
var data = {
'nonce': wc_stripe_apple_pay_single_params.stripe_apple_pay_update_shipping_method_nonce,
Expand Down Expand Up @@ -155,6 +150,20 @@ jQuery( function( $ ) {
};
}

// When payment is selected, we need to fetch cart.
applePaySession.onpaymentmethodselected = function( event ) {
$.when( wc_stripe_apple_pay_single.generate_cart() ).then( function() {

var total = {
label: wc_stripe_apple_pay_single_params.label,
amount: wc_stripe_apple_pay_single_params.total
},
lineItems = wc_stripe_apple_pay_single_params.line_items;

applePaySession.completePaymentMethodSelection( total, lineItems );
});
};

applePaySession.begin();
});
},
Expand Down
2 changes: 1 addition & 1 deletion assets/js/stripe-apple-pay-single.min.js

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

2 changes: 1 addition & 1 deletion includes/class-wc-stripe-apple-pay.php
Expand Up @@ -234,7 +234,7 @@ public function display_apple_pay_button() {

$product = wc_get_product( $post->ID );

if ( ! in_array( ( version_compare( WC_VERSION, '3.0.0', '<' ) ? $product->product_type : $product->get_type() ), $this->supported_product_types() ) ) {
if ( ! is_object( $product ) || ! in_array( ( version_compare( WC_VERSION, '3.0.0', '<' ) ? $product->product_type : $product->get_type() ), $this->supported_product_types() ) ) {
return;
}
}
Expand Down
1 change: 1 addition & 0 deletions readme.txt
Expand Up @@ -98,6 +98,7 @@ If you get stuck, you can ask for help in the Plugin Forum.
= 3.1.4 =
* Tweak - If Apple Pay is not enabled, prevent Apple Pay Init.
* Fix - Update for WooCommerce 3.0 compatibility.
* Fix - Apple Pay on product detail page causes qty issue when using normal add to cart.

= 3.1.3 =
* Fix - When using Stripe Checkout, add payment method was disabled.
Expand Down

0 comments on commit f8f010a

Please sign in to comment.