mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-06 14:57:26 +08:00
Set transaction id for authorization
This commit is contained in:
parent
79e2dd2ef5
commit
d40384aa1a
2 changed files with 21 additions and 18 deletions
|
@ -176,7 +176,7 @@ class OrderProcessor {
|
|||
|
||||
$transaction_id = $this->get_paypal_order_transaction_id( $order );
|
||||
|
||||
if ( '' !== $transaction_id ) {
|
||||
if ( $transaction_id ) {
|
||||
$this->set_order_transaction_id( $transaction_id, $wc_order );
|
||||
}
|
||||
|
||||
|
@ -216,32 +216,34 @@ class OrderProcessor {
|
|||
}
|
||||
|
||||
/**
|
||||
* Retrieve transaction id from PayPal order.
|
||||
* Retrieves transaction id from PayPal order.
|
||||
*
|
||||
* @param Order $order Order to get transaction id from.
|
||||
* @param Order $order The order to get transaction id from.
|
||||
*
|
||||
* @return string
|
||||
* @return string|null
|
||||
*/
|
||||
private function get_paypal_order_transaction_id( Order $order ): string {
|
||||
$purchase_units = $order->purchase_units();
|
||||
|
||||
if ( ! isset( $purchase_units[0] ) ) {
|
||||
return '';
|
||||
private function get_paypal_order_transaction_id( Order $order ): ?string {
|
||||
$purchase_unit = $order->purchase_units()[0] ?? null;
|
||||
if ( ! $purchase_unit ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$payments = $purchase_units[0]->payments();
|
||||
|
||||
$payments = $purchase_unit->payments();
|
||||
if ( null === $payments ) {
|
||||
return '';
|
||||
return null;
|
||||
}
|
||||
|
||||
$captures = $payments->captures();
|
||||
|
||||
if ( isset( $captures[0] ) ) {
|
||||
return $captures[0]->id();
|
||||
$capture = $payments->captures()[0] ?? null;
|
||||
if ( $capture ) {
|
||||
return $capture->id();
|
||||
}
|
||||
|
||||
return '';
|
||||
$authorization = $payments->authorizations()[0] ?? null;
|
||||
if ( $authorization ) {
|
||||
return $authorization->id();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -159,7 +159,8 @@ class OrderProcessorTest extends TestCase
|
|||
$wcOrder
|
||||
->expects('update_status')
|
||||
->with('on-hold', 'Awaiting payment.');
|
||||
|
||||
$wcOrder->expects('set_transaction_id')
|
||||
->with($transactionId);
|
||||
|
||||
$this->assertTrue($testee->process($wcOrder));
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue