@@ -509,33 +509,39 @@ The `$request` will capture the POST data sent by Sage Pay:
509509$gateway = Omnipay\Omnipay::create('SagePay_Server');
510510$gateway->setVendor('your-vendor-name');
511511$gateway->setTestMode(true); // To access your test account.
512- $request = $gateway->acceptNotification();
512+ $notifyRequest = $gateway->acceptNotification();
513513```
514514
515515Your original ` transactionId ` is available to look up the transaction in the database:
516516
517517``` php
518518// Use this transaction ID to look up the `$securityKey` you saved:
519519
520- $transactionId = $request ->getTransactionId();
520+ $transactionId = $notifyRequest ->getTransactionId();
521521$transaction = customFetchMyTransaction($transactionId); // Local storage
522522$securityKey = $transaction->getSecurityKey(); // From your local storage
523+
524+ // Alternatively, if you did not save the `securityKey` as a distinct field,
525+ // then use the `transactionReference` you saved.
526+ // The `transactionReference` for this driver will be a compound JSON string
527+ // with the `securityKey` as an integral part of it, so the driver can use it
528+ // directly.
529+
530+ $transactionReference = $transaction->getTransactionReference(); // From your local storage
523531```
524532
525533Now the signature can be checked:
526534
527535``` php
528- // The transactionReference contains a one-time token known as the `securitykey` that is
529- // used in the signature hash. You can alternatively `setSecurityKey('...')` if you saved
530- // that as a separate field.
531-
532- $request->setSecurityKey($securityKey);
536+ $notifyRequest->setSecurityKey($securityKey);
537+ // or
538+ $notifyRequest->setTransactionReference($transactionReference);
533539
534- if (! $request ->isValid()) {
540+ if (! $notifyRequest ->isValid()) {
535541 // Respond to Sage Pay indicating we are not accepting anything about this message.
536542 // You might want to log `$request->getData()` first, for later analysis.
537543
538- $request ->invalid($nextUrl, 'Signature not valid - goodbye');
544+ $notifyRequest ->invalid($nextUrl, 'Signature not valid - goodbye');
539545}
540546```
541547
@@ -544,7 +550,7 @@ then indicate this with an error. Note an "error" is to indicate that although t
544550appears to be legitimate, you do not accept it or cannot handle it for any reason:
545551
546552``` php
547- $request ->error($nextUrl, 'This transaction does not exist on the system');
553+ $notifyRequest ->error($nextUrl, 'This transaction does not exist on the system');
548554```
549555
550556> ** Note:** it has been observed that the same notification message may be sent
@@ -558,39 +564,59 @@ If you accept the notification, then you can update your local records and let S
558564``` php
559565// All raw data - just log it for later analysis:
560566
561- $request ->getData();
567+ $notifyRequest ->getData();
562568
563569// Save the final transactionReference against the transaction in the database. It will
564570// be needed if you want to capture the payment (for an authorize) or void or refund or
565571// repeat the payment later.
566572
567- $finalTransactionReference = $request ->getTransactionReference();
573+ $finalTransactionReference = $notifyRequest ->getTransactionReference();
568574
569575// The payment or authorization result:
570- // Result is $request::STATUS_COMPLETED, $request::STATUS_PENDING or $request::STATUS_FAILED
576+ // Result is $notifyRequest::STATUS_COMPLETED, $notifyRequest::STATUS_PENDING
577+ // or $notifyRequest::STATUS_FAILED
571578
572- $request ->getTransactionStatus();
579+ $notifyRequest ->getTransactionStatus();
573580
574581// If you want more detail, look at the raw data. An error message may be found in:
575582
576- $request ->getMessage();
583+ $notifyRequest ->getMessage();
577584
578585// The transaction may be the result of a `createCard()` request.
579586// The cardReference can be found like this:
580587
581- if ($request ->getTxType() === $request ::TXTYPE_TOKEN) {
582- $cardReference = $request ->getCardReference();
588+ if ($notifyRequest ->getTxType() === $notifyRequest ::TXTYPE_TOKEN) {
589+ $cardReference = $notifyRequest ->getCardReference();
583590}
584591
585592// Now let Sage Pay know you have accepted and saved the result:
586593
587- $request ->confirm($nextUrl);
594+ $notifyRequest ->confirm($nextUrl);
588595```
589596
590597The ` $nextUrl ` is where you want Sage Pay to send the user to next.
591598It will often be the same URL whether the transaction was approved or not,
592599since the result will be safely saved in the database.
593600
601+ The ` confirm() ` , ` error() ` and ` reject() ` methods will all exit the
602+ application immediately to prevent additional output being added to
603+ the response. You can disable this by setting the ` exitOnResponse `
604+ option:
605+
606+ ``` php
607+ $gateway->setExitOnResponse(false);
608+ // or
609+ $notifyRequest->setExitOnResponse(false);
610+ ```
611+
612+ If you just want the body payload, this method will return it without
613+ echoing it.
614+ You must return it with a ` 200 ` HTTP Status Code:
615+
616+ ``` php
617+ $bodyPayload = getResponseBody($status, $nextUrl, $detail = null);
618+ ```
619+
594620## Sage Pay Form Methods
595621
596622Sage Pay Form requires neither a server-to-server back-channel nor
0 commit comments