Merge pull request #714 from woocommerce/PCP-735-1.9.0-test5---missing-paypal-fee

Missing PayPal fee in WC order details for PUI purchase (735)
This commit is contained in:
Emili Castells 2022-07-08 10:31:49 +02:00 committed by GitHub
commit 9dd23f3ccf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 32 additions and 10 deletions

View file

@ -2216,7 +2216,8 @@ return array(
$container->get( 'wcgateway.is-ppcp-settings-page' ),
$container->get( 'wcgateway.current-ppcp-settings-page-id' ),
$container->get( 'wcgateway.pay-upon-invoice-product-status' ),
$container->get( 'wcgateway.pay-upon-invoice-helper' )
$container->get( 'wcgateway.pay-upon-invoice-helper' ),
$container->get( 'api.factory.capture' )
);
},
'wcgateway.logging.is-enabled' => function ( ContainerInterface $container ) : bool {

View file

@ -17,8 +17,10 @@ use WC_Product;
use WC_Product_Variable;
use WC_Product_Variation;
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\PayUponInvoiceOrderEndpoint;
use WooCommerce\PayPalCommerce\ApiClient\Factory\CaptureFactory;
use WooCommerce\PayPalCommerce\Button\Exception\RuntimeException;
use WooCommerce\PayPalCommerce\Onboarding\Environment;
use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayPalGateway;
use WooCommerce\PayPalCommerce\WcGateway\Helper\PayUponInvoiceHelper;
use WooCommerce\PayPalCommerce\Onboarding\State;
use WooCommerce\PayPalCommerce\WcGateway\Helper\PayUponInvoiceProductStatus;
@ -118,6 +120,13 @@ class PayUponInvoice {
*/
protected $pui_product_status;
/**
* The capture factory.
*
* @var CaptureFactory
*/
protected $capture_factory;
/**
* PayUponInvoice constructor.
*
@ -133,6 +142,7 @@ class PayUponInvoice {
* @param string $current_ppcp_settings_page_id Current PayPal settings page id.
* @param PayUponInvoiceProductStatus $pui_product_status The PUI product status.
* @param PayUponInvoiceHelper $pui_helper The PUI helper.
* @param CaptureFactory $capture_factory The capture factory.
*/
public function __construct(
string $module_url,
@ -146,7 +156,8 @@ class PayUponInvoice {
bool $is_ppcp_settings_page,
string $current_ppcp_settings_page_id,
PayUponInvoiceProductStatus $pui_product_status,
PayUponInvoiceHelper $pui_helper
PayUponInvoiceHelper $pui_helper,
CaptureFactory $capture_factory
) {
$this->module_url = $module_url;
$this->fraud_net = $fraud_net;
@ -160,6 +171,7 @@ class PayUponInvoice {
$this->current_ppcp_settings_page_id = $current_ppcp_settings_page_id;
$this->pui_product_status = $pui_product_status;
$this->pui_helper = $pui_helper;
$this->capture_factory = $capture_factory;
}
/**
@ -210,7 +222,12 @@ class PayUponInvoice {
'ppcp_payment_capture_completed_webhook_handler',
function ( WC_Order $wc_order, string $order_id ) {
try {
$payment_instructions = $this->pui_order_endpoint->order_payment_instructions( $order_id );
$order = $this->pui_order_endpoint->order( $order_id );
$payment_instructions = array(
$order->payment_source->pay_upon_invoice->payment_reference,
$order->payment_source->pay_upon_invoice->deposit_bank_details,
);
$wc_order->update_meta_data(
'ppcp_ratepay_payment_instructions_payment_reference',
$payment_instructions
@ -218,6 +235,12 @@ class PayUponInvoice {
$wc_order->save_meta_data();
$this->logger->info( "Ratepay payment instructions added to order #{$wc_order->get_id()}." );
$capture = $this->capture_factory->from_paypal_response( $order->purchase_units[0]->payments->captures[0] );
$breakdown = $capture->seller_receivable_breakdown();
if ( $breakdown ) {
$wc_order->update_meta_data( PayPalGateway::FEES_META_KEY, $breakdown->to_array() );
$wc_order->save_meta_data();
}
} catch ( RuntimeException $exception ) {
$this->logger->error( $exception->getMessage() );
}