Overview

Namespaces

  • Guzzle
    • Batch
      • Exception
    • Cache
    • Common
      • Exception
    • Http
      • Curl
      • Exception
      • Message
        • Header
      • QueryAggregator
    • Inflection
    • Iterator
    • Log
    • Parser
      • Cookie
      • Message
      • UriTemplate
      • Url
    • Plugin
      • Async
      • Backoff
      • Cache
      • Cookie
        • CookieJar
        • Exception
      • CurlAuth
      • ErrorResponse
        • Exception
      • History
      • Log
      • Md5
      • Mock
      • Oauth
    • Service
      • Builder
      • Command
        • Factory
        • LocationVisitor
          • Request
          • Response
      • Description
      • Exception
      • Resource
    • Stream
    • Tests
      • Batch
      • Cache
      • Common
        • Cache
        • Exception
      • Http
        • Curl
        • Exception
        • Message
          • Header
      • Inflection
      • Iterator
      • Log
      • Message
      • Mock
      • Parser
        • Cookie
        • Message
      • Parsers
        • UriTemplate
      • Plugin
        • Async
        • Backoff
        • Cache
        • Cookie
          • CookieJar
        • CurlAuth
        • ErrorResponse
        • History
        • Log
        • Md5
        • Mock
        • Oauth
        • Redirect
      • Service
        • Builder
        • Command
          • LocationVisitor
            • Request
            • Response
        • Description
        • Exception
        • Mock
          • Command
            • Sub
          • Model
        • Resource
      • Stream
  • None
  • Omnipay
    • Common
      • Exception
      • Message
    • Dummy
      • Message
    • VivaPayments
      • Message
  • PHP

Classes

  • AbstractRestRequest
  • FetchTransactionsRequest
  • NativeAuthorizeRequest
  • NativePurchaseRequest
  • RedirectAuthorizeRequest
  • RedirectPurchaseRequest
  • RedirectResponse
  • RefundRequest
  • RestResponse
  • Overview
  • Namespace
  • Class
  • Tree

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
Extended by Omnipay\VivaPayments\Message\AbstractRestRequest
Extended by Omnipay\VivaPayments\Message\NativePurchaseRequest

Direct known subclasses

Omnipay\VivaPayments\Message\NativeAuthorizeRequest
Namespace: Omnipay\VivaPayments\Message
See: 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
Methods summary
public mixed
# getData( )

Get the raw data array for this message. The format of this varies from gateway to gateway, but will usually be either an associative array, or a SimpleXMLElement.

Get the raw data array for this message. The format of this varies from gateway to gateway, but will usually be either an associative array, or a SimpleXMLElement.

Returns

mixed

Overrides

Omnipay\VivaPayments\Message\AbstractRestRequest::getData()
protected string
# getEndpoint( )

Get transaction endpoint.

Get transaction endpoint.

Purchases are created using the /purchases resource.

Returns

string

Overrides

Omnipay\VivaPayments\Message\AbstractRestRequest::getEndpoint()
public Omnipay\Common\Message\ResponseInterface
# send( )

Send the request

Send the request

Note that for the Native Purchase request there are 2 separate API calls. One to create the order, and one to create the transaction.

Returns

Omnipay\Common\Message\ResponseInterface

Overrides

Omnipay\Common\Message\AbstractRequest::send()
Methods inherited from Omnipay\VivaPayments\Message\AbstractRestRequest
createResponse(), getApiKey(), getBaseEndpoint(), getHttpMethod(), getMerchantId(), getRequestLang(), getSourceCode(), sendData(), setApiKey(), setMerchantId(), setRequestLang(), setSourceCode()
Methods inherited from Omnipay\Common\Message\AbstractRequest
__construct(), formatCurrency(), getAmount(), getAmountInteger(), getCancelUrl(), getCard(), getCardReference(), getClientIp(), getCurrency(), getCurrencyDecimalPlaces(), getCurrencyNumeric(), getDescription(), getIssuer(), getItems(), getNotifyUrl(), getParameter(), getParameters(), getPaymentMethod(), getResponse(), getReturnUrl(), getTestMode(), getToken(), getTransactionId(), getTransactionReference(), initialize(), setAmount(), setCancelUrl(), setCard(), setCardReference(), setClientIp(), setCurrency(), setDescription(), setIssuer(), setItems(), setNotifyUrl(), setParameter(), setPaymentMethod(), setReturnUrl(), setTestMode(), setToken(), setTransactionId(), setTransactionReference(), toFloat(), validate()
Properties summary
protected boolean $orderComplete

This says whether the order is complete and we have moved to making a transaction

This says whether the order is complete and we have moved to making a transaction

This flips to "true" once we create the first API call.

# false
Properties inherited from Omnipay\VivaPayments\Message\AbstractRestRequest
$liveEndpoint, $testEndpoint
Properties inherited from Omnipay\Common\Message\AbstractRequest
$httpClient, $httpRequest, $negativeAmountAllowed, $parameters, $response, $zeroAmountAllowed
Omnipay Viva Payments Gateway Module API Documentation API documentation generated by ApiGen