Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SagePay\Form redirect #144

Closed
dan-pascu opened this issue Oct 22, 2019 · 2 comments
Closed

SagePay\Form redirect #144

dan-pascu opened this issue Oct 22, 2019 · 2 comments
Assignees
Labels

Comments

@dan-pascu
Copy link

Hi,

I'm trying to use Laravel 6 with SagePay\Form and, as per the documentation, I have the following:

$gateway = OmniPay::create('SagePay\Form')->initialize([
'vendor' => 'my_vendor',
'testMode' => true,
'encryptionKey' => 'my_encryption_key',
]);

$response = $gateway->authorize([
'amount' => '9.99',
'currency' => 'GBP',
'transactionId' => 12345,,
'returnUrl' => 'https://example.com/success',
'failureUrl' => 'https://example.com/failure',
]);

$response->redirect();

And I get this error Call to undefined method Omnipay\SagePay\Message\Form\AuthorizeRequest::redirect()
When I dd the reponse I have this:
image

I think I'm missing something but I cannot figure out what, can you guide me please?

@judgej
Copy link
Member

judgej commented Oct 22, 2019

It looks like you have set $response to a request. To get the response, you need to "send" it. That does not actually send anything to Sage Pay, but it keeps the steps consistent across different gateways.

$gateway = OmniPay::create('SagePay\Form')->initialize([...]);
$request = $gateway->authorize([...]);
$response = $request->send(); // The step you have have overlooked
$response->redirect();

Or for the last step. you can construct your own form or redirect to suit your framework using:

$method = $response->getRedirectMethod();
$url = $response->getRedirectUrl()
$hiddenFormItems = $response->getRedirectData();

So for Laravel constructing a self-submitting form, or a form with a button to redirect, would be the preference.

<form method="{{ $method }}" action="{{ $url }}">
@foreach($hiddenFormItems as $name => $value)
<input type="hidden" name="{{ $name }}" value="{{ $value }}" />
@endforeach
<button type="submit">Go pay!</button>
</form>

@judgej judgej self-assigned this Oct 22, 2019
@dan-pascu
Copy link
Author

Following your instructions I manage to make it work. Thank you.

Previously I tried the send() method but it required a card, and for Form method I don't have a card to send. My mistake. Also in the card details are stored the billing and shipping information that are required and I didn't thought on this.

Another mistake I made is the encryptionKey. I included a wrong one and I received an encryption error: "openssl_encrypt(): IV passed is 20 bytes long which is longer than the 16 expected by selected cipher, truncating". I then used the correct Form Integration Encryption Password from SagePay and everything went fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants