'processing payment for woocommerce order

I'm looking for some PHP logic code to process the payment for woocommerce order. My current logic is failling.

My scenario is customer places an online order on woocommerce enabled website by selecting braintree credit card payment method, enters credit card info and submits the order. The store receives the order until this stage, card payment is not authorized. Order may get changes as per their customers changes request or stores inability to process certain items from the order which is removed. Once order is finalized after changes, order is confirmed that is when I want to process the payment, capture the payment and settle it down. I have php code to process the payment, capture the payment amount and settle it down. But when I process the payment order is failing which I suspect due to lack of credit card information. How can I achieve the functionality?. I don't want to take customer to payment page and ask him or her to enter credit card info again.

NOTE: Woocommerce documentation states "Finally, you need to add payment code inside your process_payment( $order_id ) method. This takes the posted form data and attempts payment directly via the payment provider." (here the issue is how or where to find payment code?

Error message:Braintree (Credit Card) Payment Failed (Status code 91577, 81709, 81714, 81725, 81703: Merchant account does not support payment instrument., Expiration date is required., Credit card number is required., Credit card must include number, paymentMethodNonce, or venmoSdkPaymentMethodCode., Credit card type is not accepted by this merchant account.) Order status changed from On hold to Failed. (credit card info was entered during checkout)

Here is the code that actually failing

add_action( 'woocommerce_order_status_processing_to_on-hold', 'process_credit_card_authorize', 10, 2 );

function process_credit_card_authorize( $order_id, $order) { $available_gateways = WC()->payment_gateways->get_available_payment_gateways(); $result = $available_gateways[ 'braintree_credit_card' ]->process_payment( $order_id );

if ( $result['result'] == 'success' ) 
{
    $result = apply_filters( 'woocommerce_payment_successful_result', $result, $order_id );
    wp_redirect( $result['redirect'] );
    exit;
}

}



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source