1

I have built a custom gateway for sage pay form.

The plugin gathers all the data from Store and then posts it off to sagepay in an encrypted string.

User than completes payment on the the sagepay website before being posted back to a specified success URL with an encrypted string attatched. When the string is decoded you can view the order status.

How do i notify cart that the order has been paid for and to log it as complete?

1

You should take a look at other gateways which handle this situation, for example Paypal Express:

https://github.com/expressodev/ci-merchant/blob/master/libraries/merchant/merchant_paypal_express.php

When you build the purchase request, you need to tell the gateway to return the customer to $this->param('return_url'). For example, in Paypal this involves:

$request['RETURNURL'] = $this->param('return_url');

This URL will look something like:

https://example.com/index.php?ACT=123&H=abcdef123456

This is a special EE action URL, which is passed through to Store. Store looks up the payment hash to see which gateway requested the payment, then automatically loads that gateway, and calls purchase_return(). So you need to implement that method on your gateway class:

public function purchase_return()
{
    // do something here
}

Inside the purchase_return() method you should check $_GET or $_POST for the encrypted string that the gateway sent back to you. Here is another good example of decoding a response and returning the appropriate reply:

https://github.com/expressodev/ci-merchant/blob/master/libraries/merchant/merchant_dps_pxpay.php#L62

Basically, if the transaction is successful you should return something like:

return new Merchant_response(Merchant_response::COMPLETE, $response_message_from_gateway, $transaction_id_from_gateway);

If the response failed, return something like:

return new Merchant_response(Merchant_response::FAILED, $response_message_from_gateway, $transaction_id_if_there_was_one);

Then Store will know to update the order accordingly, and will either mark the order as complete and redirect the customer to the success page, or send them back to the checkout to try again.

  • #boom! - that worked a treat. Thankyou very much. – Edd Smith May 27 '13 at 12:00
1

I think you should just need to make sure your custom driver extends Merchant_driver (or in the case of SagePay, possibly just extend Merchant_sagepay_base).

Then I think you just need to make sure you're returning the request at the end of the method for the Merchant Lib and Store to deal with.

return $request;
  • I think you may have misunderstood. I am using $this->redirect(self::PROCESS_URL.'?'.$complete); This redirects to the sage pay URL along with the encrypted string attached. Once sage pay is done it returns to a success url. There is no API and this process does not happen instantaneously. So when the success page loads, i need some function to fire that completes the order. Does that make sense? – Edd Smith May 26 '13 at 21:02
  • There is the [store_order_payment_end](https://exp-resso.com/docs/store/extension_hooks.html#store_order_payment_end) hook but I'm not entirely sure that's what you'd need. I'm sure Adrian can clarify shortly. – Ian May 26 '13 at 21:21
  • Looking in store_payments.php it looks like it could be all you need with the process_return method taking in the same parameters: process_return($order, $payment). – Ian May 26 '13 at 21:31
  • But how will the store know that payment has been completed? I am posting a encrypted string to sagepay and on completion it is posting one back. Say i decrypt the response, see its all ok what do i then do to get the store to complete the order? Thanks for trying to help :). – Edd Smith May 26 '13 at 21:58
  • Should the success URL be to a specific script rather than a EE template? – Edd Smith May 26 '13 at 22:00

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.