0

I placed the order programatically. Everything seems to work fine, even the "payment method" on the order page is show up correctly. However the order email I received, the payment method is unknown. It suppose to show "Add to account"

I don't know why, I thought that could be the email rules is executed before the token is available with the payment method name to use. On Drupal commerce email configuration, it's set to use the token [commerce-order:payment-method-short-title]

$payment_method = commerce_payment_method_instance_load('bank_transfer|commerce_payment_bank_transfer');

 $charge = $order->commerce_order_total['und'][0];


$transaction = commerce_payment_transaction_new('bank_transfer', $order->order_id);
$transaction->instance_id = $payment_method['instance_id'];
$transaction->amount = $charge['amount'];
$transaction->currency_code = $charge['currency_code'];
$transaction->status = COMMERCE_PAYMENT_STATUS_SUCCESS;
$transaction->message = 'Name: @name';
$transaction->message_variables = array('@name' => 'Add to Account');

commerce_payment_transaction_save($transaction);
commerce_payment_commerce_payment_transaction_insert($transaction);
commerce_checkout_complete($order);
commerce_order_save($order);
0

I now found the solution, I need to add the payment method to the order object, so the token system can pick it up and use in the order email.

Before save the order, we need to add the payment method.

$order->data['payment_method'] = 'bank_transfer|commerce_payment_bank_transfer';
commerce_order_save($order);

It can be placed before the transaction section.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.