Add save payment method attributes to PayPal payment source

This commit is contained in:
Emili Castells Guasch 2023-10-19 16:15:20 +02:00
parent 08280fa138
commit 99d05ca44d
6 changed files with 81 additions and 17 deletions

View file

@ -61,6 +61,8 @@ class UserIdToken {
/**
* Returns `id_token` which uniquely identifies the payer.
*
* @return string
*
* @throws PayPalApiException If the request fails.
* @throws RuntimeException If something unexpected happens.
*/

View file

@ -260,26 +260,25 @@ class OrderEndpoint {
);
throw $error;
}
$json = json_decode( $response['body'] );
$status_code = (int) wp_remote_retrieve_response_code( $response );
if ( 201 !== $status_code ) {
if ( ! in_array( $status_code, array( 200, 201 ), true ) ) {
$error = new PayPalApiException(
$json,
$status_code
);
$this->logger->log(
'warning',
$this->logger->warning(
sprintf(
'Failed to create order. PayPal API response: %1$s',
$error->getMessage()
),
array(
'args' => $args,
'response' => $response,
)
);
throw $error;
}
$order = $this->order_factory->from_paypal_response( $json );
do_action( 'woocommerce_paypal_payments_paypal_order_created', $order );

View file

@ -15,14 +15,15 @@ use WooCommerce\PayPalCommerce\ApiClient\Exception\RuntimeException;
* Class OrderStatus
*/
class OrderStatus {
const INTERNAL = 'INTERNAL';
const CREATED = 'CREATED';
const SAVED = 'SAVED';
const APPROVED = 'APPROVED';
const VOIDED = 'VOIDED';
const COMPLETED = 'COMPLETED';
const PENDING_APPROVAL = 'PENDING_APPROVAL';
const VALID_STATUS = array(
const INTERNAL = 'INTERNAL';
const CREATED = 'CREATED';
const SAVED = 'SAVED';
const APPROVED = 'APPROVED';
const VOIDED = 'VOIDED';
const COMPLETED = 'COMPLETED';
const PENDING_APPROVAL = 'PENDING_APPROVAL';
const PAYER_ACTION_REQUIRED = 'PAYER_ACTION_REQUIRED';
const VALID_STATUS = array(
self::INTERNAL,
self::CREATED,
self::SAVED,
@ -30,6 +31,7 @@ class OrderStatus {
self::VOIDED,
self::COMPLETED,
self::PENDING_APPROVAL,
self::PAYER_ACTION_REQUIRED,
);
/**