Add payment method to create order request body data filter

This commit is contained in:
Emili Castells Guasch 2023-11-23 11:40:21 +01:00
parent d0e7200669
commit 687b56d8c0
4 changed files with 12 additions and 11 deletions

View file

@ -219,14 +219,11 @@ class OrderEndpoint {
if ( $payment_token ) { if ( $payment_token ) {
$data['payment_source']['token'] = $payment_token->to_array(); $data['payment_source']['token'] = $payment_token->to_array();
} }
if ( $payment_method ) {
$data['payment_method'] = $payment_method;
}
/** /**
* The filter can be used to modify the order creation request body data. * The filter can be used to modify the order creation request body data.
*/ */
$data = apply_filters( 'ppcp_create_order_request_body_data', $data ); $data = apply_filters( 'ppcp_create_order_request_body_data', $data, $payment_method );
$url = trailingslashit( $this->host ) . 'v2/checkout/orders'; $url = trailingslashit( $this->host ) . 'v2/checkout/orders';
$args = array( $args = array(
'method' => 'POST', 'method' => 'POST',

View file

@ -89,7 +89,7 @@ class SavePaymentMethodsModule implements ModuleInterface {
// Adds attributes needed to save payment method. // Adds attributes needed to save payment method.
add_filter( add_filter(
'ppcp_create_order_request_body_data', 'ppcp_create_order_request_body_data',
function( array $data ): array { function( array $data, string $payment_method ): array {
// phpcs:ignore WordPress.Security.NonceVerification.Missing // phpcs:ignore WordPress.Security.NonceVerification.Missing
$wc_order_action = wc_clean( wp_unslash( $_POST['wc_order_action'] ?? '' ) ); $wc_order_action = wc_clean( wp_unslash( $_POST['wc_order_action'] ?? '' ) );
if ( $wc_order_action === 'wcs_process_renewal' ) { if ( $wc_order_action === 'wcs_process_renewal' ) {
@ -111,8 +111,6 @@ class SavePaymentMethodsModule implements ModuleInterface {
} }
} }
$payment_method = $data['payment_method'] ?? '';
if ( $payment_method === CreditCardGateway::ID ) { if ( $payment_method === CreditCardGateway::ID ) {
$data['payment_source'] = array( $data['payment_source'] = array(
'card' => array( 'card' => array(
@ -123,6 +121,13 @@ class SavePaymentMethodsModule implements ModuleInterface {
), ),
), ),
); );
$target_customer_id = get_user_meta( get_current_user_id(), '_ppcp_target_customer_id', true );
if ( $target_customer_id ) {
$data['payment_source']['card']['attributes']['customer'] = array(
'id' => $target_customer_id,
);
}
} }
if ( $payment_method === PayPalGateway::ID ) { if ( $payment_method === PayPalGateway::ID ) {
@ -139,7 +144,9 @@ class SavePaymentMethodsModule implements ModuleInterface {
} }
return $data; return $data;
} },
10,
2
); );
add_action( add_action(

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long