Skip to content

Commit

Permalink
Merge branch 'develop' into fix/2169-required-field-breaking-prb
Browse files Browse the repository at this point in the history
  • Loading branch information
Mayisha authored Feb 21, 2024
2 parents 7f9b81d + 9ff7029 commit df51d3e
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 18 deletions.
1 change: 1 addition & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* Fix - Critical error when deactivating the extension after deactivating WooCommerce.
* Fix - Add missing fee and payout information to the order details page in admin.
* Fix - Hiding "Early Access" label and "Refresh payment methods" button when UPE is disabled.
* Fix - Prevent undefined $latest_charge property warnings when signing up to subscriptions with no initial payment (eg free trials).
* Tweak - Orders with `trash` status are not retrieving anymore when calling `get_order_by_intent_id` function.
* Add - Update the interface for customizing Stripe payment methods.

Expand Down
24 changes: 14 additions & 10 deletions includes/abstracts/abstract-wc-stripe-payment-gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -710,11 +710,15 @@ public function get_charge_object( $charge_id = '', $params = [] ) {
* @return object
*/
public function get_latest_charge_from_intent( $intent ) {
$latest_charge = null;

if ( ! empty( $intent->charges->data ) ) {
return end( $intent->charges->data );
} else {
return $this->get_charge_object( $intent->latest_charge );
$latest_charge = end( $intent->charges->data );
} elseif ( ! empty( $intent->latest_charge ) ) {
$latest_charge = $this->get_charge_object( $intent->latest_charge );
}

return $latest_charge;
}

/**
Expand Down Expand Up @@ -1538,15 +1542,15 @@ public function confirm_intent( $intent, $order, $prepared_source ) {
public function save_intent_to_order( $order, $intent ) {
if ( 'payment_intent' === $intent->object ) {
WC_Stripe_Helper::add_payment_intent_to_order( $intent->id, $order );
} elseif ( 'setup_intent' === $intent->object ) {
$order->update_meta_data( '_stripe_setup_intent', $intent->id );
}

// Add the mandate id necessary for renewal payments with Indian cards if it's present.
$charge = $this->get_latest_charge_from_intent( $intent );
// Add the mandate id necessary for renewal payments with Indian cards if it's present.
$charge = $this->get_latest_charge_from_intent( $intent );

if ( isset( $charge->payment_method_details->card->mandate ) ) {
$order->update_meta_data( '_stripe_mandate_id', $charge->payment_method_details->card->mandate );
if ( isset( $charge->payment_method_details->card->mandate ) ) {
$order->update_meta_data( '_stripe_mandate_id', $charge->payment_method_details->card->mandate );
}
} elseif ( 'setup_intent' === $intent->object ) {
$order->update_meta_data( '_stripe_setup_intent', $intent->id );
}

if ( is_callable( [ $order, 'save' ] ) ) {
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

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

10 changes: 5 additions & 5 deletions tests/e2e/tests/checkout/card-failures.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,25 +45,25 @@ test.describe.configure( { mode: 'parallel' } );
test.describe( 'customer cannot checkout with invalid cards', () => {
test( `a declined card shows the correct error message @smoke`, async ( {
page,
} ) => testCardBlocks( page, 'cards.declined' ) );
} ) => testCard( page, 'cards.declined' ) );

test( `a card with insufficient funds shows the correct error message`, async ( {
page,
} ) => testCardBlocks( page, 'cards.declined-funds' ) );
} ) => testCard( page, 'cards.declined-funds' ) );

test( `a card with invalid number shows the correct error message`, async ( {
page,
} ) => testCard( page, 'cards.declined-incorrect' ) );

test( `an expired card shows the correct error message`, async ( {
page,
} ) => testCardBlocks( page, 'cards.declined-expired' ) );
} ) => testCard( page, 'cards.declined-expired' ) );

test( `a card with incorrect CVC shows the correct error message @smoke`, async ( {
page,
} ) => testCardBlocks( page, 'cards.declined-cvc' ) );
} ) => testCard( page, 'cards.declined-cvc' ) );

test( `an error processing the card shows the correct error message`, async ( {
page,
} ) => testCardBlocks( page, 'cards.declined-processing' ) );
} ) => testCard( page, 'cards.declined-processing' ) );
} );
2 changes: 1 addition & 1 deletion tests/e2e/utils/payments.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export async function emptyCart( page ) {
}

await expect(
page.locator( '.wc-block-components-notice-banner__content' )
page.locator( '.wc-empty-cart-message .cart-empty' )
).toHaveText( 'Your cart is currently empty.' );
}

Expand Down

0 comments on commit df51d3e

Please sign in to comment.