mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-08-31 06:52:50 +08:00
Merge pull request #767 from woocommerce/pcp-834-id-after-manual-capture
Update transaction id after manual capture
This commit is contained in:
commit
6704bc1f53
2 changed files with 20 additions and 8 deletions
|
@ -31,7 +31,7 @@ use WooCommerce\PayPalCommerce\WcGateway\Notice\AuthorizeOrderActionNotice;
|
||||||
*/
|
*/
|
||||||
class AuthorizedPaymentsProcessor {
|
class AuthorizedPaymentsProcessor {
|
||||||
|
|
||||||
use PaymentsStatusHandlingTrait;
|
use PaymentsStatusHandlingTrait, TransactionIdHandlingTrait;
|
||||||
|
|
||||||
const SUCCESSFUL = 'SUCCESSFUL';
|
const SUCCESSFUL = 'SUCCESSFUL';
|
||||||
const ALREADY_CAPTURED = 'ALREADY_CAPTURED';
|
const ALREADY_CAPTURED = 'ALREADY_CAPTURED';
|
||||||
|
@ -200,6 +200,9 @@ class AuthorizedPaymentsProcessor {
|
||||||
|
|
||||||
$this->handle_capture_status( $capture, $wc_order );
|
$this->handle_capture_status( $capture, $wc_order );
|
||||||
|
|
||||||
|
$transaction_id = $capture->id();
|
||||||
|
$this->update_transaction_id( $transaction_id, $wc_order );
|
||||||
|
|
||||||
if ( self::SUCCESSFUL === $result_status ) {
|
if ( self::SUCCESSFUL === $result_status ) {
|
||||||
if ( $capture->status()->is( CaptureStatus::COMPLETED ) ) {
|
if ( $capture->status()->is( CaptureStatus::COMPLETED ) ) {
|
||||||
$wc_order->add_order_note(
|
$wc_order->add_order_note(
|
||||||
|
|
|
@ -4,6 +4,7 @@ declare(strict_types=1);
|
||||||
namespace WooCommerce\PayPalCommerce\WcGateway\Processor;
|
namespace WooCommerce\PayPalCommerce\WcGateway\Processor;
|
||||||
|
|
||||||
|
|
||||||
|
use Mockery\MockInterface;
|
||||||
use Psr\Container\ContainerInterface;
|
use Psr\Container\ContainerInterface;
|
||||||
use Psr\Log\NullLogger;
|
use Psr\Log\NullLogger;
|
||||||
use WC_Order;
|
use WC_Order;
|
||||||
|
@ -26,7 +27,11 @@ use WooCommerce\PayPalCommerce\WcGateway\Notice\AuthorizeOrderActionNotice;
|
||||||
|
|
||||||
class AuthorizedPaymentsProcessorTest extends TestCase
|
class AuthorizedPaymentsProcessorTest extends TestCase
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* @var WC_Order&MockInterface
|
||||||
|
*/
|
||||||
private $wcOrder;
|
private $wcOrder;
|
||||||
|
|
||||||
private $paypalOrderId = 'abc';
|
private $paypalOrderId = 'abc';
|
||||||
private $authorizationId = 'qwe';
|
private $authorizationId = 'qwe';
|
||||||
private $amount = 42.0;
|
private $amount = 42.0;
|
||||||
|
@ -37,7 +42,7 @@ class AuthorizedPaymentsProcessorTest extends TestCase
|
||||||
private $paymentsEndpoint;
|
private $paymentsEndpoint;
|
||||||
private $notice;
|
private $notice;
|
||||||
private $config;
|
private $config;
|
||||||
private $subscription_helperauthorization;
|
private $captureId = '123qwe';
|
||||||
private $testee;
|
private $testee;
|
||||||
|
|
||||||
public function setUp(): void {
|
public function setUp(): void {
|
||||||
|
@ -79,7 +84,7 @@ class AuthorizedPaymentsProcessorTest extends TestCase
|
||||||
$this->paymentsEndpoint
|
$this->paymentsEndpoint
|
||||||
->expects('capture')
|
->expects('capture')
|
||||||
->with($this->authorizationId, equalTo(new Money($this->amount, $this->currency)))
|
->with($this->authorizationId, equalTo(new Money($this->amount, $this->currency)))
|
||||||
->andReturn($this->createCapture(CaptureStatus::COMPLETED));
|
->andReturn($this->createCapture($this->captureId, CaptureStatus::COMPLETED));
|
||||||
|
|
||||||
$this->assertEquals(AuthorizedPaymentsProcessor::SUCCESSFUL, $this->testee->process($this->wcOrder));
|
$this->assertEquals(AuthorizedPaymentsProcessor::SUCCESSFUL, $this->testee->process($this->wcOrder));
|
||||||
}
|
}
|
||||||
|
@ -99,7 +104,7 @@ class AuthorizedPaymentsProcessorTest extends TestCase
|
||||||
$this->paymentsEndpoint
|
$this->paymentsEndpoint
|
||||||
->expects('capture')
|
->expects('capture')
|
||||||
->with($authorizations[2]->id(), equalTo(new Money($this->amount, $this->currency)))
|
->with($authorizations[2]->id(), equalTo(new Money($this->amount, $this->currency)))
|
||||||
->andReturn($this->createCapture(CaptureStatus::COMPLETED));
|
->andReturn($this->createCapture($this->captureId, CaptureStatus::COMPLETED));
|
||||||
|
|
||||||
$this->assertEquals(AuthorizedPaymentsProcessor::SUCCESSFUL, $this->testee->process($this->wcOrder));
|
$this->assertEquals(AuthorizedPaymentsProcessor::SUCCESSFUL, $this->testee->process($this->wcOrder));
|
||||||
}
|
}
|
||||||
|
@ -150,12 +155,13 @@ class AuthorizedPaymentsProcessorTest extends TestCase
|
||||||
$this->paymentsEndpoint
|
$this->paymentsEndpoint
|
||||||
->expects('capture')
|
->expects('capture')
|
||||||
->with($this->authorizationId, equalTo(new Money($this->amount, $this->currency)))
|
->with($this->authorizationId, equalTo(new Money($this->amount, $this->currency)))
|
||||||
->andReturn($this->createCapture(CaptureStatus::COMPLETED));
|
->andReturn($this->createCapture($this->captureId, CaptureStatus::COMPLETED));
|
||||||
|
|
||||||
$this->wcOrder->shouldReceive('payment_complete')->andReturn(true);
|
$this->wcOrder->shouldReceive('payment_complete')->andReturn(true);
|
||||||
$this->wcOrder->expects('add_order_note');
|
$this->wcOrder->expects('add_order_note')->twice();
|
||||||
$this->wcOrder->expects('update_meta_data');
|
$this->wcOrder->expects('update_meta_data');
|
||||||
$this->wcOrder->expects('save');
|
$this->wcOrder->expects('set_transaction_id')->with($this->captureId);
|
||||||
|
$this->wcOrder->shouldReceive('save')->atLeast()->times(1);
|
||||||
|
|
||||||
$this->assertTrue(
|
$this->assertTrue(
|
||||||
$this->testee->capture_authorized_payment($this->wcOrder)
|
$this->testee->capture_authorized_payment($this->wcOrder)
|
||||||
|
@ -248,8 +254,11 @@ class AuthorizedPaymentsProcessorTest extends TestCase
|
||||||
return new Authorization($id, new AuthorizationStatus($status));
|
return new Authorization($id, new AuthorizationStatus($status));
|
||||||
}
|
}
|
||||||
|
|
||||||
private function createCapture(string $status): Capture {
|
private function createCapture(string $id, string $status): Capture {
|
||||||
$capture = Mockery::mock(Capture::class);
|
$capture = Mockery::mock(Capture::class);
|
||||||
|
$capture
|
||||||
|
->shouldReceive('id')
|
||||||
|
->andReturn($id);
|
||||||
$capture
|
$capture
|
||||||
->shouldReceive('status')
|
->shouldReceive('status')
|
||||||
->andReturn(new CaptureStatus($status));
|
->andReturn(new CaptureStatus($status));
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue