0

I am using drupal commerce to built a e-commerce site .

My problem is when a transaction is failed or get a late response then the transaction is not created.

Can i create it manually or i have to ? if yes then how?

Or is their any other way to attach my transaction detail to order .

Any help most appriciate. Thank you.

  • This question is very vague. What payment module are you using? This sounds like a bug in the module or perhaps PHP is dying before the request times out. – nvahalik Nov 6 '15 at 17:46
0

You need to load the failed transaction from order id as shown below:

<?php
  $query = new EntityFieldQuery;
  $result = $query
    ->entityCondition('entity_type', 'commerce_payment_transaction')
    ->propertyCondition('order_id', $order->order_id)
    ->propertyOrderBy('transaction_id', 'DESC')
    ->range(0, 1)
    ->execute();
?>

Then load transaction using commerce_payment_transaction_load($transaction_id) & update transaction object as shown below:

<?php
//Use following line instead of loading transaction in order to create new transaction object
//$transaction = commerce_payment_transaction_new('commerce_payment_example', $order->order_id);
$transaction = commerce_payment_transaction_load($transaction_id);
$transaction->amount = $charge['amount'];
$transaction->currency_code = $charge['currency_code'];
$transaction->status = COMMERCE_PAYMENT_STATUS_SUCCESS;
commerce_payment_transaction_save($transaction);
?>

You can set a cron to periodically check failed transaction & check status of same at Payment Gateway & update accordingly.

| improve this answer | |
  • Thanks for your interest but in my case transaction is not created yet. i.e, if customer close the window just after payment. – Lucifer Mar 11 '15 at 11:28

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.