Class NativePurchaseRequest
Viva Payments Native (REST) Purchase Request
Native Checkout allows you to create a custom payment form, so that your customers never leave your page for making a card payment. However there is a JavaScript plugin that must be used on the payment page to make this happen, as it encodes the card details to a card reference directly between the customer's browser and the gateway, leaving just the card reference in the form.
Read the documentation at this page about configuring your vivapayments account for Native payments: https://github.com/VivaPayments/API/wiki/Native-Checkout
Steps to complete the payment. This is a brief guide -- for full details see the above documentation page.
- Build the payment form as per Step 3 of the documentation page. Note the use of the special
data-vp
attribute. - Add a reference to jQuery in the section of your site
- Add a reference to the Native Checkout script in the section of your site
- Initialize the process by calling the cards.setup() method once the document is fully loaded (e.g. on $(document).ready()). Note that you need to fill the publicKey attribute in the JavaScript with the public key you get from the viva payments web site.
- Native Checkout sets the generated token in the hidden field
hidToken
and then submits the form. - Add a button to your form that requests a token.
- On the server side, call the API to process the payment.
Example
Note that this only covers the server side transaction -- everything else is done on the browser.
// Create a gateway for the Viva Payments REST Gateway // (routes to GatewayFactory::create) $gateway = Omnipay::create('VivaPayments_Native'); // Initialise the gateway $gateway->initialize(array( 'merchantId' => 'TEST', 'apiKey' => 'TEST', 'testMode' => true, // Or false when you are ready for live transactions )); // Do a purchase transaction on the gateway $transaction = $gateway->purchase(array( 'amount' => '10.00', 'transactionId' => 'TestPurchaseTransaction123456', 'clientIp' => $_SERVER['REMOTE_ADDR'], 'cardReference' => $card_reference, )); $response = $transaction->send(); // For a Native gateway request if ($response->isSuccessful()) { echo "Gateway response is successful.\n"; $sale_id = $response->getTransactionReference(); echo "Transaction reference = " . $sale_id . "\n"; }
- Omnipay\Common\Message\AbstractRequest implements Omnipay\Common\Message\RequestInterface
- Omnipay\VivaPayments\Message\AbstractRestRequest
- Omnipay\VivaPayments\Message\NativePurchaseRequest
Direct known subclasses
Omnipay\VivaPayments\Message\NativeAuthorizeRequestSee:
Omnipay\VivaPayments\RestGateway
Link: https://github.com/VivaPayments/API/wiki
Link: https://www.vivawallet.com/en-us/company
Link: https://github.com/VivaPayments/API/wiki/Native-Checkout
Located at Message/NativePurchaseRequest.php
public
mixed
|
|
protected
string
|
|
public
|
protected
boolean
|
$orderComplete
This says whether the order is complete and we have moved to making a transaction |
#
false
|
$liveEndpoint,
$testEndpoint
|
$httpClient,
$httpRequest,
$negativeAmountAllowed,
$parameters,
$response,
$zeroAmountAllowed
|