Skip to content

Commit

Permalink
Fix checkout error with Afterpay (#7214)
Browse files Browse the repository at this point in the history
This change fixes an error in the checkout due to missing shipping information in the request to create and confirm a payment intent.
  • Loading branch information
mgascam authored Sep 14, 2023
1 parent 325ef03 commit ddbd33f
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 2 deletions.
4 changes: 4 additions & 0 deletions changelog/hotfix-7187-checkout-error-with-afterpay
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fix

Fix an error in the checkout when Afterpay is selected as payment method.
18 changes: 18 additions & 0 deletions includes/class-wc-payment-gateway-wcpay.php
Original file line number Diff line number Diff line change
Expand Up @@ -1128,6 +1128,9 @@ public function process_payment_for_order( $cart, $payment_information, $schedul
$request->set_payment_methods( $payment_methods );
$request->set_cvc_confirmation( $payment_information->get_cvc_confirmation() );

// Add specific payment method parameters to the request.
$this->modify_create_intent_parameters_when_processing_payment( $request, $payment_information, $order );

// The below if-statement ensures the support for UPE payment methods.
if ( $this->upe_needs_redirection( $payment_methods ) ) {
$request->set_return_url(
Expand Down Expand Up @@ -3599,4 +3602,19 @@ private function is_platform_payment_method( bool $is_using_saved_payment_method
private function upe_needs_redirection( $payment_methods ) {
return 1 === count( $payment_methods ) && 'card' !== $payment_methods[0];
}

/**
* Modifies the create intent parameters when processing a payment.
*
* Currently used by child UPE_Split_Payment_Gateway to add required shipping information for Afterpay.
*
* @param Create_And_Confirm_Intention $request The request object for creating and confirming intention.
* @param Payment_Information $payment_information The payment information object.
* @param mixed $order The order object or data.
*
* @return void
*/
protected function modify_create_intent_parameters_when_processing_payment( Create_And_Confirm_Intention $request, Payment_Information $payment_information, $order ) {
// Do nothing.
}
}
3 changes: 2 additions & 1 deletion includes/payment-methods/class-upe-payment-gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@
use WCPay\Duplicate_Payment_Prevention_Service;
use WP_User;
use WC_Payments_Localization_Service;

use WCPay\Payment_Information;
use WCPay\Core\Server\Request\Create_And_Confirm_Intention;

/**
* UPE Payment method extended from WCPay generic Gateway.
Expand Down
21 changes: 20 additions & 1 deletion includes/payment-methods/class-upe-split-payment-gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
use WCPay\Duplicate_Payment_Prevention_Service;
use WP_User;
use WC_Payments_Localization_Service;

use WCPay\Payment_Information;
use WCPay\Core\Server\Request\Create_And_Confirm_Intention;


/**
Expand Down Expand Up @@ -529,4 +530,22 @@ public function get_payment_method() {
public function get_stripe_id() {
return $this->stripe_id;
}


/**
* Modifies the create intent parameters when processing a payment.
*
* If the selected Stripe payment type is AFTERPAY, it updates the shipping data in the request.
*
* @param Create_And_Confirm_Intention $request The request object for creating and confirming intention.
* @param Payment_Information $payment_information The payment information object.
* @param mixed $order The order object or data.
*
* @return void
*/
protected function modify_create_intent_parameters_when_processing_payment( Create_And_Confirm_Intention $request, Payment_Information $payment_information, $order ) {
if ( Payment_Method::AFTERPAY === $this->get_selected_stripe_payment_type_id() ) {
$request->set_shipping( $this->get_shipping_data_from_order( $order ) );
}
}
}

0 comments on commit ddbd33f

Please sign in to comment.