woocommerce / woocommerce-paypal-payments

https://wordpress.org/plugins/woocommerce-paypal-payments/
GNU General Public License v2.0
62 stars 48 forks source link

Unable to check transaction status (526) #453

Open ifnull opened 2 years ago

ifnull commented 2 years ago

Description

We are migrating from woocommerce-gateway-paypal-express-checkout. At checkout, we authorize then capture after an order has been fulfilled. Before sending an order to the fulfillment system we check the status of the authorization of a transaction. The way we do this in the Paypal Express Checkout plugin is by checking the order meta key _paypal_status and getting the transaction details using the plugin's internal gateway client. If the transaction is pending for any reason other than "authorization" we cancel the order.

Excerpt of how we do this today:

$paypal_status = get_post_meta ( $orderId, '_paypal_status', TRUE );
$trans_id      = get_post_meta ( $orderId, '_transaction_id', TRUE );
$trans_details = wc_gateway_ppec()->client->get_transaction_details( array( 'TRANSACTIONID' => $trans_id ) );
$reason = $trans_details['PENDINGREASON'];

if( $paypal_status !== 'pending' && $reason !== 'authorization' ){
    $order->add_order_note( 'Cancelled because Paypal payment status was ' . $paypal_status . 'Paypal PENDINGREASON was ' . $reason, 0, TRUE );
    $order->update_status( 'cancelled' );
}

With the woocommerce-paypal-payments plugin, I do not see a _paypal_status meta key on the order. However, it looks like the function order_is_approved() will provide what I need but since it is a private function, I'm unable to call it.

To Reproduce

$payment_gateways = new WC_Payment_Gateways();
$ppcp_gateway = $payment_gateways->get_available_payment_gateways()['ppcp-gateway'];
$ppcp_gateway->order_processor;

Expected Behavior

Order approval status is returned.

Actual Behavior

Uncaught Error: Cannot access protected property WooCommerce\PayPalCommerce\WcGateway\Gateway\PayPalGateway::$order_processor 

Environment

AlexP11223 commented 2 years ago

will provide what I need but since it is a private function, I'm unable to call it.

I think it would not help much even if it was public? You still need an order object retrieved from PayPal API.

If you want to do that, you can get api.endpoint.order from the container like discussed here and call its order method.