1
Answers
Vote up!
1
Vote down!

set orders as 'complete' from custom module

Hello,

I have an issue related with Orders (I guess). This is the scenario: I have a custom payment gateway based on a remote web form displayed in a Chekout pane, works OK. When the data is received from the remote payment gateway and the transaction is completed, the user is redirected to a page of Drupal with the result of the process, that´s OK too. My issue is that when the remote payment gateway send the parameters to the page, and the parameters are received, I do not know how to programmatically set the order as 'completed' (the Order always is on 'shopping cart 'status). btw the Profile is stored OK too. any thoughts? or this is with Rules?,

this is the code that I have in this moment:

function commerce_checkout_pane_empty_cart() {
if($_GET['authorization'] == 'OK'){

  global $user;
  $user = user_load($user->uid);

  $order = commerce_cart_order_load($user->uid);

  $profile = commerce_customer_profile_new('billing', $user->uid);
  $profile->commerce_customer_address = array(LANGUAGE_NONE => array(0 => addressfield_default_values()));

  commerce_customer_profile_save($profile);

  $order->commerce_customer_billing[LANGUAGE_NONE][0]['profile_id'] = $profile->profile_id;

  commerce_order_save($order);
  commerce_order_status_update($order,'checkout_complete');
  commerce_checkout_complete($order);
  }
}

thanks in advance.

Asked by: cigocf
on March 26, 2013

1 Answer

Vote up!
1
Vote down!

just for comment that I have used Rules to implement the "complete" order status for when is received the feedback from the remote payment gateway.

Specifically 1) Event: "Content is viewed", 2) the conditions to validate the POST parameters received form the payment gateway, and 3) Actions: "Complete checkout for an order" and "Update the order state" (to update the order to "complete" state))

Using this way still is not possible to organize the Customer Profile related, but this is essential? I guess that this is other issue...

I encourage to anybody to give some thoughts about how to implement this programmatically, this is useful from Git perspective and more flexible control.

Answer by: cigocf
Posted: Mar 27, 2013