Add PayPal order id into WC order meta

This commit is contained in:
Emili Castells Guasch 2024-08-23 16:23:23 +02:00
parent 150d29c0b4
commit 53de52e2d3
9 changed files with 40 additions and 1 deletions

View file

@ -145,8 +145,15 @@ class Orders {
$status_code = (int) wp_remote_retrieve_response_code( $response ); $status_code = (int) wp_remote_retrieve_response_code( $response );
if ( $status_code !== 200 ) { if ( $status_code !== 200 ) {
$body = json_decode( $response['body'] );
$message = $body->details[0]->description ?? '';
if ( $message ) {
throw new RuntimeException( $message );
}
throw new PayPalApiException( throw new PayPalApiException(
json_decode( $response['body'] ), $body,
$status_code $status_code
); );
} }

View file

@ -13,6 +13,7 @@ use WC_Payment_Gateway;
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\Orders; use WooCommerce\PayPalCommerce\ApiClient\Endpoint\Orders;
use WooCommerce\PayPalCommerce\ApiClient\Factory\PurchaseUnitFactory; use WooCommerce\PayPalCommerce\ApiClient\Factory\PurchaseUnitFactory;
use WooCommerce\PayPalCommerce\Button\Exception\RuntimeException; use WooCommerce\PayPalCommerce\Button\Exception\RuntimeException;
use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayPalGateway;
use WooCommerce\PayPalCommerce\WcGateway\Gateway\TransactionUrlProvider; use WooCommerce\PayPalCommerce\WcGateway\Gateway\TransactionUrlProvider;
use WooCommerce\PayPalCommerce\WcGateway\Processor\RefundProcessor; use WooCommerce\PayPalCommerce\WcGateway\Processor\RefundProcessor;
@ -177,6 +178,9 @@ class BancontactGateway extends WC_Payment_Gateway {
$body = json_decode( $response['body'] ); $body = json_decode( $response['body'] );
$wc_order->update_meta_data( PayPalGateway::ORDER_ID_META_KEY, $body->id );
$wc_order->save_meta_data();
$payer_action = ''; $payer_action = '';
foreach ( $body->links as $link ) { foreach ( $body->links as $link ) {
if ( $link->rel === 'payer-action' ) { if ( $link->rel === 'payer-action' ) {

View file

@ -13,6 +13,7 @@ use WC_Payment_Gateway;
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\Orders; use WooCommerce\PayPalCommerce\ApiClient\Endpoint\Orders;
use WooCommerce\PayPalCommerce\ApiClient\Factory\PurchaseUnitFactory; use WooCommerce\PayPalCommerce\ApiClient\Factory\PurchaseUnitFactory;
use WooCommerce\PayPalCommerce\Button\Exception\RuntimeException; use WooCommerce\PayPalCommerce\Button\Exception\RuntimeException;
use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayPalGateway;
use WooCommerce\PayPalCommerce\WcGateway\Gateway\TransactionUrlProvider; use WooCommerce\PayPalCommerce\WcGateway\Gateway\TransactionUrlProvider;
use WooCommerce\PayPalCommerce\WcGateway\Processor\RefundProcessor; use WooCommerce\PayPalCommerce\WcGateway\Processor\RefundProcessor;
@ -178,6 +179,9 @@ class BlikGateway extends WC_Payment_Gateway {
$body = json_decode( $response['body'] ); $body = json_decode( $response['body'] );
$wc_order->update_meta_data( PayPalGateway::ORDER_ID_META_KEY, $body->id );
$wc_order->save_meta_data();
$payer_action = ''; $payer_action = '';
foreach ( $body->links as $link ) { foreach ( $body->links as $link ) {
if ( $link->rel === 'payer-action' ) { if ( $link->rel === 'payer-action' ) {

View file

@ -13,6 +13,7 @@ use WC_Payment_Gateway;
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\Orders; use WooCommerce\PayPalCommerce\ApiClient\Endpoint\Orders;
use WooCommerce\PayPalCommerce\ApiClient\Factory\PurchaseUnitFactory; use WooCommerce\PayPalCommerce\ApiClient\Factory\PurchaseUnitFactory;
use WooCommerce\PayPalCommerce\Button\Exception\RuntimeException; use WooCommerce\PayPalCommerce\Button\Exception\RuntimeException;
use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayPalGateway;
use WooCommerce\PayPalCommerce\WcGateway\Gateway\TransactionUrlProvider; use WooCommerce\PayPalCommerce\WcGateway\Gateway\TransactionUrlProvider;
use WooCommerce\PayPalCommerce\WcGateway\Processor\RefundProcessor; use WooCommerce\PayPalCommerce\WcGateway\Processor\RefundProcessor;
@ -177,6 +178,9 @@ class EPSGateway extends WC_Payment_Gateway {
$body = json_decode( $response['body'] ); $body = json_decode( $response['body'] );
$wc_order->update_meta_data( PayPalGateway::ORDER_ID_META_KEY, $body->id );
$wc_order->save_meta_data();
$payer_action = ''; $payer_action = '';
foreach ( $body->links as $link ) { foreach ( $body->links as $link ) {
if ( $link->rel === 'payer-action' ) { if ( $link->rel === 'payer-action' ) {

View file

@ -13,6 +13,7 @@ use WC_Payment_Gateway;
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\Orders; use WooCommerce\PayPalCommerce\ApiClient\Endpoint\Orders;
use WooCommerce\PayPalCommerce\ApiClient\Factory\PurchaseUnitFactory; use WooCommerce\PayPalCommerce\ApiClient\Factory\PurchaseUnitFactory;
use WooCommerce\PayPalCommerce\Button\Exception\RuntimeException; use WooCommerce\PayPalCommerce\Button\Exception\RuntimeException;
use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayPalGateway;
use WooCommerce\PayPalCommerce\WcGateway\Gateway\TransactionUrlProvider; use WooCommerce\PayPalCommerce\WcGateway\Gateway\TransactionUrlProvider;
use WooCommerce\PayPalCommerce\WcGateway\Processor\RefundProcessor; use WooCommerce\PayPalCommerce\WcGateway\Processor\RefundProcessor;
@ -179,6 +180,9 @@ class IDealGateway extends WC_Payment_Gateway {
$body = json_decode( $response['body'] ); $body = json_decode( $response['body'] );
$wc_order->update_meta_data( PayPalGateway::ORDER_ID_META_KEY, $body->id );
$wc_order->save_meta_data();
$payer_action = ''; $payer_action = '';
foreach ( $body->links as $link ) { foreach ( $body->links as $link ) {
if ( $link->rel === 'payer-action' ) { if ( $link->rel === 'payer-action' ) {

View file

@ -13,6 +13,7 @@ use WC_Payment_Gateway;
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\Orders; use WooCommerce\PayPalCommerce\ApiClient\Endpoint\Orders;
use WooCommerce\PayPalCommerce\ApiClient\Factory\PurchaseUnitFactory; use WooCommerce\PayPalCommerce\ApiClient\Factory\PurchaseUnitFactory;
use WooCommerce\PayPalCommerce\Button\Exception\RuntimeException; use WooCommerce\PayPalCommerce\Button\Exception\RuntimeException;
use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayPalGateway;
use WooCommerce\PayPalCommerce\WcGateway\Gateway\TransactionUrlProvider; use WooCommerce\PayPalCommerce\WcGateway\Gateway\TransactionUrlProvider;
use WooCommerce\PayPalCommerce\WcGateway\Processor\RefundProcessor; use WooCommerce\PayPalCommerce\WcGateway\Processor\RefundProcessor;
@ -180,6 +181,9 @@ class MultibancoGateway extends WC_Payment_Gateway {
WC()->cart->empty_cart(); WC()->cart->empty_cart();
$wc_order->update_meta_data( PayPalGateway::ORDER_ID_META_KEY, $body->id );
$wc_order->save_meta_data();
return array( return array(
'result' => 'success', 'result' => 'success',
'redirect' => esc_url( $payer_action ), 'redirect' => esc_url( $payer_action ),

View file

@ -13,6 +13,7 @@ use WC_Payment_Gateway;
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\Orders; use WooCommerce\PayPalCommerce\ApiClient\Endpoint\Orders;
use WooCommerce\PayPalCommerce\ApiClient\Factory\PurchaseUnitFactory; use WooCommerce\PayPalCommerce\ApiClient\Factory\PurchaseUnitFactory;
use WooCommerce\PayPalCommerce\Button\Exception\RuntimeException; use WooCommerce\PayPalCommerce\Button\Exception\RuntimeException;
use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayPalGateway;
use WooCommerce\PayPalCommerce\WcGateway\Gateway\TransactionUrlProvider; use WooCommerce\PayPalCommerce\WcGateway\Gateway\TransactionUrlProvider;
use WooCommerce\PayPalCommerce\WcGateway\Processor\RefundProcessor; use WooCommerce\PayPalCommerce\WcGateway\Processor\RefundProcessor;
@ -177,6 +178,9 @@ class MyBankGateway extends WC_Payment_Gateway {
$body = json_decode( $response['body'] ); $body = json_decode( $response['body'] );
$wc_order->update_meta_data( PayPalGateway::ORDER_ID_META_KEY, $body->id );
$wc_order->save_meta_data();
$payer_action = ''; $payer_action = '';
foreach ( $body->links as $link ) { foreach ( $body->links as $link ) {
if ( $link->rel === 'payer-action' ) { if ( $link->rel === 'payer-action' ) {

View file

@ -13,6 +13,7 @@ use WC_Payment_Gateway;
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\Orders; use WooCommerce\PayPalCommerce\ApiClient\Endpoint\Orders;
use WooCommerce\PayPalCommerce\ApiClient\Factory\PurchaseUnitFactory; use WooCommerce\PayPalCommerce\ApiClient\Factory\PurchaseUnitFactory;
use WooCommerce\PayPalCommerce\Button\Exception\RuntimeException; use WooCommerce\PayPalCommerce\Button\Exception\RuntimeException;
use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayPalGateway;
use WooCommerce\PayPalCommerce\WcGateway\Gateway\TransactionUrlProvider; use WooCommerce\PayPalCommerce\WcGateway\Gateway\TransactionUrlProvider;
use WooCommerce\PayPalCommerce\WcGateway\Processor\RefundProcessor; use WooCommerce\PayPalCommerce\WcGateway\Processor\RefundProcessor;
@ -178,6 +179,9 @@ class P24Gateway extends WC_Payment_Gateway {
$body = json_decode( $response['body'] ); $body = json_decode( $response['body'] );
$wc_order->update_meta_data( PayPalGateway::ORDER_ID_META_KEY, $body->id );
$wc_order->save_meta_data();
$payer_action = ''; $payer_action = '';
foreach ( $body->links as $link ) { foreach ( $body->links as $link ) {
if ( $link->rel === 'payer-action' ) { if ( $link->rel === 'payer-action' ) {

View file

@ -13,6 +13,7 @@ use WC_Payment_Gateway;
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\Orders; use WooCommerce\PayPalCommerce\ApiClient\Endpoint\Orders;
use WooCommerce\PayPalCommerce\ApiClient\Factory\PurchaseUnitFactory; use WooCommerce\PayPalCommerce\ApiClient\Factory\PurchaseUnitFactory;
use WooCommerce\PayPalCommerce\Button\Exception\RuntimeException; use WooCommerce\PayPalCommerce\Button\Exception\RuntimeException;
use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayPalGateway;
use WooCommerce\PayPalCommerce\WcGateway\Gateway\TransactionUrlProvider; use WooCommerce\PayPalCommerce\WcGateway\Gateway\TransactionUrlProvider;
use WooCommerce\PayPalCommerce\WcGateway\Processor\RefundProcessor; use WooCommerce\PayPalCommerce\WcGateway\Processor\RefundProcessor;
@ -177,6 +178,9 @@ class TrustlyGateway extends WC_Payment_Gateway {
$body = json_decode( $response['body'] ); $body = json_decode( $response['body'] );
$wc_order->update_meta_data( PayPalGateway::ORDER_ID_META_KEY, $body->id );
$wc_order->save_meta_data();
$payer_action = ''; $payer_action = '';
foreach ( $body->links as $link ) { foreach ( $body->links as $link ) {
if ( $link->rel === 'payer-action' ) { if ( $link->rel === 'payer-action' ) {