How to Call the Process_Payment($order_id ) inside a JS function
-
Hi, well i am back on this cool forum! Got a question, i am builing a custom payment gateway plugin for WP. But the callback i receive from the payment gateway in terms of wether the payment was processed correctly is via Javascript not PHP TOKEN or IPN call back like most payment gateways do, so it is via this JS function or once the payment is processed correctly this function response is called:
var onAuthorize = function(response) {
//Here i can make my custom script to trigger something like redirect to a thank you page cause order was processed correctly but in WordPress i need to trigger a PHP function from the Woocommerce API to process the payment: public function process_payment( $order_id ) So i would to call that function inside this JS function in order to process and close the order.
};
Thefore i need to trigger this PHP function (from the woocomerce API to process the payment, more info here https://docs.woocommerce.com/document/payment-gateway-api/) to process the payment but i would need to call the function, mentioned below this comment. inside the previous JS function:
public function process_payment( $order_id ) { global $woocommerce; $customer_order = new WC_Order( $order_id ); // Payment successful $customer_order->add_order_note( __( 'Xchange complete payment.', 'cwoa-authorizenet-aim' ) ); // paid order marked $customer_order->payment_complete(); // this is important part for empty cart $woocommerce->cart->empty_cart(); // Redirect to thank you page return array( 'result' => 'success', 'redirect' => $this->get_return_url( $customer_order ), );
So the question is can you call a PHP function inside a JS / Ajax function, better to call it on the same file in which i am handling the payment processing, cause sending the checkout process to another page or refreshing the page i guess will loose cart details information which happened to me via GET, via POST will have to double check.
Anyone had to deal with this problem before, calling a PHP function inside JS? Anyone know if there is JS version of the default Woocommerce API process payment PHP function: public function process_payment( $order_id )
Would love the help. Thanx
- The topic ‘How to Call the Process_Payment($order_id ) inside a JS function’ is closed to new replies.