Reputation: 1601
I'm working on an android app based on a 3 Tier architecture. I have set up a products page and the Pay Now button integrated with PayPal. I also receive Success
message after successful payment.
I'm now stuck at the order function. Which function of Woocommerce makes the order?
I'm simply trying to pass the price, product_id and other details to that particular function which will take care of the rest of the process.
Any help would be much appreciated. Thank you.
Upvotes: 2
Views: 365
Reputation: 15875
Here is some code that will generate an order. You'll have to substitute in your payment gateway class
// create a new checkout instance and order id
global $current_user;
$product_id = $_POST['productId'];
$product = wc_get_product($product_id);
$order = wc_create_order(array(
'customer_id' => $current_user->ID,
));
$order->add_product( $product, 1 );
$order->calculate_totals();
$my_gateway = new WC_Gateway_WhateverGatewayYouAreUsing();
$payment = $my_gateway->process_payment($order->id);
if($payment["result"] == "success") {
$order->update_status('completed');
wc_add_notice("Thank you!");
}
else {
$order->update_status("cancelled");
wc_add_notice("oh no! plz send me da moneez", 'notice');
}
Upvotes: 1