Hi,
I am working on a contrib module to provide support for the SagePay form payment gateway which is of the redirected gateway type.
I am trying to understand how to call back to the Drupal Commerce site - ie what URL structure to use.
Originally, I created a new menu callback in my custom module, but on further investigation it seems there's a standard way of doing this.
What I think I need to do is set up the "success" and "failure" urls I send to the gateway so the following function processes the callback:
function commerce_payment_redirect_pane_checkout_form(&$form, &$form_state, $checkout_pane, $order) {
...
Following the logic here:
// If the user came to the return URL...
if (arg(3) == 'return' && arg(4) == $order->data['payment_redirect_key']) {
// Check for a validate handler on return.
$validate_callback = commerce_payment_method_callback($payment_method, 'redirect_form_validate');
I think that means I should set the return url to be :
$redirect_key = $order->data['payment_redirect_key'];
$success_url = $GLOBALS['base_url'] . '/checkout/commerce_sagepay/return/' . $redirect_key,
However, I when I do this, I get a 404 from the checkout_router function. Am I missing something or is there no menu entry to pick up the redirected callback yet?
Thanks!
Richard
| Comment | File | Size | Author |
|---|---|---|---|
| #1 | commerce_sagepay.zip | 7.44 KB | ikos |
Comments
Comment #1
ikos commentedCode attached for reference.
Comment #2
rszrama commentedSorry I didn't get back to you sooner, Richard. I think you've already figured it out, but yeah, the gist of it is that user initiated cancellations can come back to the cancel URL and the completed process can send them back to the return URL. At the return step, your module can perform a validation to determine if payment failed or succeeded. If it failed, the user will go back to the previous step in checkout. If it completed, they'll go forward.
Here's the code in my PayPal WPS module I use to construct my URLs:
And here's my validate handler: