Fix creating wc payment token by checking payment in response

This commit is contained in:
Emili Castells Guasch 2023-12-18 14:04:53 +01:00
parent 2c4767a55b
commit 946e8172c7
2 changed files with 97 additions and 96 deletions

View file

@ -28,6 +28,7 @@ document.addEventListener(
init()
});
setTimeout(() => {
loadScript({
clientId: ppcp_add_payment_method.client_id,
merchantId: ppcp_add_payment_method.merchant_id,
@ -175,6 +176,7 @@ document.addEventListener(
});
});
})
}, 1000)
}
);

View file

@ -100,8 +100,7 @@ class CreatePaymentToken implements EndpointInterface {
if ( is_user_logged_in() && isset( $result->customer->id ) ) {
update_user_meta( get_current_user_id(), '_ppcp_target_customer_id', $result->customer->id );
$payment_method = $data['payment_method'] ?? '';
if ( $payment_method === PayPalGateway::ID ) {
if ( isset($result->payment_source->paypal) ) {
$email = '';
if ( isset( $result->payment_source->paypal->email_address ) ) {
$email = $result->payment_source->paypal->email_address;
@ -114,7 +113,7 @@ class CreatePaymentToken implements EndpointInterface {
);
}
if ( $payment_method === CreditCardGateway::ID ) {
if ( isset($result->payment_source->card) ) {
$token = new \WC_Payment_Token_CC();
$token->set_token( $result->id );
$token->set_user_id( get_current_user_id() );