mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-05 08:59:14 +08:00
Merge pull request #937 from woocommerce/PCP-736-1-9-0-test-5-missing-pui-refund-functionality-from-wc-order
Missing PUI refund functionality from WC order (736)
This commit is contained in:
commit
b420ec4d22
3 changed files with 58 additions and 3 deletions
|
@ -2083,7 +2083,9 @@ return array(
|
||||||
$container->get( 'wcgateway.transaction-url-provider' ),
|
$container->get( 'wcgateway.transaction-url-provider' ),
|
||||||
$container->get( 'woocommerce.logger.woocommerce' ),
|
$container->get( 'woocommerce.logger.woocommerce' ),
|
||||||
$container->get( 'wcgateway.pay-upon-invoice-helper' ),
|
$container->get( 'wcgateway.pay-upon-invoice-helper' ),
|
||||||
$container->get( 'wcgateway.checkout-helper' )
|
$container->get( 'wcgateway.checkout-helper' ),
|
||||||
|
$container->get( 'onboarding.state' ),
|
||||||
|
$container->get( 'wcgateway.processor.refunds' )
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
'wcgateway.pay-upon-invoice-fraudnet-session-id' => static function ( ContainerInterface $container ): FraudNetSessionId {
|
'wcgateway.pay-upon-invoice-fraudnet-session-id' => static function ( ContainerInterface $container ): FraudNetSessionId {
|
||||||
|
|
|
@ -17,10 +17,12 @@ use WooCommerce\PayPalCommerce\ApiClient\Endpoint\PayUponInvoiceOrderEndpoint;
|
||||||
use WooCommerce\PayPalCommerce\ApiClient\Exception\PayPalApiException;
|
use WooCommerce\PayPalCommerce\ApiClient\Exception\PayPalApiException;
|
||||||
use WooCommerce\PayPalCommerce\ApiClient\Factory\PurchaseUnitFactory;
|
use WooCommerce\PayPalCommerce\ApiClient\Factory\PurchaseUnitFactory;
|
||||||
use WooCommerce\PayPalCommerce\Onboarding\Environment;
|
use WooCommerce\PayPalCommerce\Onboarding\Environment;
|
||||||
|
use WooCommerce\PayPalCommerce\Onboarding\State;
|
||||||
use WooCommerce\PayPalCommerce\WcGateway\Gateway\TransactionUrlProvider;
|
use WooCommerce\PayPalCommerce\WcGateway\Gateway\TransactionUrlProvider;
|
||||||
use WooCommerce\PayPalCommerce\WcGateway\Helper\CheckoutHelper;
|
use WooCommerce\PayPalCommerce\WcGateway\Helper\CheckoutHelper;
|
||||||
use WooCommerce\PayPalCommerce\WcGateway\Helper\PayUponInvoiceHelper;
|
use WooCommerce\PayPalCommerce\WcGateway\Helper\PayUponInvoiceHelper;
|
||||||
use WooCommerce\PayPalCommerce\WcGateway\Processor\OrderMetaTrait;
|
use WooCommerce\PayPalCommerce\WcGateway\Processor\OrderMetaTrait;
|
||||||
|
use WooCommerce\PayPalCommerce\WcGateway\Processor\RefundProcessor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class PayUponInvoiceGateway.
|
* Class PayUponInvoiceGateway.
|
||||||
|
@ -87,6 +89,20 @@ class PayUponInvoiceGateway extends WC_Payment_Gateway {
|
||||||
*/
|
*/
|
||||||
protected $checkout_helper;
|
protected $checkout_helper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The onboarding state.
|
||||||
|
*
|
||||||
|
* @var State
|
||||||
|
*/
|
||||||
|
protected $state;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The refund processor.
|
||||||
|
*
|
||||||
|
* @var RefundProcessor
|
||||||
|
*/
|
||||||
|
protected $refund_processor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* PayUponInvoiceGateway constructor.
|
* PayUponInvoiceGateway constructor.
|
||||||
*
|
*
|
||||||
|
@ -98,6 +114,8 @@ class PayUponInvoiceGateway extends WC_Payment_Gateway {
|
||||||
* @param LoggerInterface $logger The logger.
|
* @param LoggerInterface $logger The logger.
|
||||||
* @param PayUponInvoiceHelper $pui_helper The PUI helper.
|
* @param PayUponInvoiceHelper $pui_helper The PUI helper.
|
||||||
* @param CheckoutHelper $checkout_helper The checkout helper.
|
* @param CheckoutHelper $checkout_helper The checkout helper.
|
||||||
|
* @param State $state The onboarding state.
|
||||||
|
* @param RefundProcessor $refund_processor The refund processor.
|
||||||
*/
|
*/
|
||||||
public function __construct(
|
public function __construct(
|
||||||
PayUponInvoiceOrderEndpoint $order_endpoint,
|
PayUponInvoiceOrderEndpoint $order_endpoint,
|
||||||
|
@ -107,7 +125,9 @@ class PayUponInvoiceGateway extends WC_Payment_Gateway {
|
||||||
TransactionUrlProvider $transaction_url_provider,
|
TransactionUrlProvider $transaction_url_provider,
|
||||||
LoggerInterface $logger,
|
LoggerInterface $logger,
|
||||||
PayUponInvoiceHelper $pui_helper,
|
PayUponInvoiceHelper $pui_helper,
|
||||||
CheckoutHelper $checkout_helper
|
CheckoutHelper $checkout_helper,
|
||||||
|
State $state,
|
||||||
|
RefundProcessor $refund_processor
|
||||||
) {
|
) {
|
||||||
$this->id = self::ID;
|
$this->id = self::ID;
|
||||||
|
|
||||||
|
@ -137,6 +157,12 @@ class PayUponInvoiceGateway extends WC_Payment_Gateway {
|
||||||
$this->transaction_url_provider = $transaction_url_provider;
|
$this->transaction_url_provider = $transaction_url_provider;
|
||||||
$this->pui_helper = $pui_helper;
|
$this->pui_helper = $pui_helper;
|
||||||
$this->checkout_helper = $checkout_helper;
|
$this->checkout_helper = $checkout_helper;
|
||||||
|
|
||||||
|
$this->state = $state;
|
||||||
|
if ( $state->current_state() === State::STATE_ONBOARDED ) {
|
||||||
|
$this->supports = array( 'refunds' );
|
||||||
|
}
|
||||||
|
$this->refund_processor = $refund_processor;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -276,6 +302,22 @@ class PayUponInvoiceGateway extends WC_Payment_Gateway {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Process refund.
|
||||||
|
*
|
||||||
|
* @param int $order_id Order ID.
|
||||||
|
* @param float $amount Refund amount.
|
||||||
|
* @param string $reason Refund reason.
|
||||||
|
* @return boolean True or false based on success, or a WP_Error object.
|
||||||
|
*/
|
||||||
|
public function process_refund( $order_id, $amount = null, $reason = '' ) {
|
||||||
|
$order = wc_get_order( $order_id );
|
||||||
|
if ( ! is_a( $order, \WC_Order::class ) ) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return $this->refund_processor->process( $order, (float) $amount, (string) $reason );
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return transaction url for this gateway and given order.
|
* Return transaction url for this gateway and given order.
|
||||||
*
|
*
|
||||||
|
|
|
@ -11,10 +11,12 @@ use WooCommerce\PayPalCommerce\ApiClient\Entity\Order;
|
||||||
use WooCommerce\PayPalCommerce\ApiClient\Entity\PurchaseUnit;
|
use WooCommerce\PayPalCommerce\ApiClient\Entity\PurchaseUnit;
|
||||||
use WooCommerce\PayPalCommerce\ApiClient\Factory\PurchaseUnitFactory;
|
use WooCommerce\PayPalCommerce\ApiClient\Factory\PurchaseUnitFactory;
|
||||||
use WooCommerce\PayPalCommerce\Onboarding\Environment;
|
use WooCommerce\PayPalCommerce\Onboarding\Environment;
|
||||||
|
use WooCommerce\PayPalCommerce\Onboarding\State;
|
||||||
use WooCommerce\PayPalCommerce\TestCase;
|
use WooCommerce\PayPalCommerce\TestCase;
|
||||||
use WooCommerce\PayPalCommerce\WcGateway\Gateway\TransactionUrlProvider;
|
use WooCommerce\PayPalCommerce\WcGateway\Gateway\TransactionUrlProvider;
|
||||||
use WooCommerce\PayPalCommerce\WcGateway\Helper\CheckoutHelper;
|
use WooCommerce\PayPalCommerce\WcGateway\Helper\CheckoutHelper;
|
||||||
use WooCommerce\PayPalCommerce\WcGateway\Helper\PayUponInvoiceHelper;
|
use WooCommerce\PayPalCommerce\WcGateway\Helper\PayUponInvoiceHelper;
|
||||||
|
use WooCommerce\PayPalCommerce\WcGateway\Processor\RefundProcessor;
|
||||||
use function Brain\Monkey\Functions\when;
|
use function Brain\Monkey\Functions\when;
|
||||||
|
|
||||||
class PayUponInvoiceGatewayTest extends TestCase
|
class PayUponInvoiceGatewayTest extends TestCase
|
||||||
|
@ -28,6 +30,8 @@ class PayUponInvoiceGatewayTest extends TestCase
|
||||||
private $testee;
|
private $testee;
|
||||||
private $pui_helper;
|
private $pui_helper;
|
||||||
private $checkout_helper;
|
private $checkout_helper;
|
||||||
|
private $state;
|
||||||
|
private $refund_processor;
|
||||||
|
|
||||||
public function setUp(): void
|
public function setUp(): void
|
||||||
{
|
{
|
||||||
|
@ -42,6 +46,11 @@ class PayUponInvoiceGatewayTest extends TestCase
|
||||||
$this->pui_helper = Mockery::mock(PayUponInvoiceHelper::class);
|
$this->pui_helper = Mockery::mock(PayUponInvoiceHelper::class);
|
||||||
$this->checkout_helper = Mockery::mock(CheckoutHelper::class);
|
$this->checkout_helper = Mockery::mock(CheckoutHelper::class);
|
||||||
|
|
||||||
|
$this->state = Mockery::mock(State::class);
|
||||||
|
$this->state->shouldReceive('current_state')->andReturn(State::STATE_ONBOARDED);
|
||||||
|
|
||||||
|
$this->refund_processor = Mockery::mock(RefundProcessor::class);
|
||||||
|
|
||||||
$this->setInitStubs();
|
$this->setInitStubs();
|
||||||
when('wc_clean')->returnArg();
|
when('wc_clean')->returnArg();
|
||||||
|
|
||||||
|
@ -53,7 +62,9 @@ class PayUponInvoiceGatewayTest extends TestCase
|
||||||
$this->transaction_url_provider,
|
$this->transaction_url_provider,
|
||||||
$this->logger,
|
$this->logger,
|
||||||
$this->pui_helper,
|
$this->pui_helper,
|
||||||
$this->checkout_helper
|
$this->checkout_helper,
|
||||||
|
$this->state,
|
||||||
|
$this->refund_processor
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue