Create payment order

PHP code sample for creating a payment order.

Overview

The following PHP code sample includes comments explaining the different elements and parameters involved in the Create payment order API call.

Please also see also our tutorial on the same subject

Code sample

The below example uses OAuth 2.0 authentication

<?php

// Bearer must be generated with OAuth 2 and scope: urn:viva:payments:core:api:redirectcheckout
// https://developer.viva.com/tutorials-for-payments/enable-oauth2-authentication/
$accessToken = 'xxx';
$postFields  = [
    'amount'              => 100,
    'customerTrns'        => 'This is a description displayed to the customer',
    'customer'            => [
        'email'       => 'someone@vivawallet.com',
        'fullName'    => 'George Seferis',
        'phone'       => '69xxxxxxxxx',
        'countryCode' => 'GR',
        'requestLang' => 'el-GR'
    ],
    'paymentTimeout'      => 1800,
    'preauth'             => true,
    'allowRecurring'      => true,
    'maxInstallments'     => 0,
    'paymentNotification' => true,
    'tipAmount'           => 1,
    'disableExactAmount'  => true,
    'disableCash'         => false,
    'disableWallet'       => false,
    'sourceCode'          => 'Default',
    'merchantTrns'        => 'This is a short description that helps you uniquely identify the transaction',
    'tags'                => ['tag1', 'tag2']
    'cardTokens'          => ["ct_5d0a4e3a7e04469f82da228ca98fd661"]
];

$curl = curl_init();

curl_setopt_array($curl, array(
    CURLOPT_URL            => 'https://demo-api.vivapayments.com/checkout/v2/orders',
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_ENCODING       => '',
    CURLOPT_MAXREDIRS      => 10,
    CURLOPT_TIMEOUT        => 0,
    CURLOPT_FOLLOWLOCATION => true,
    CURLOPT_HTTP_VERSION   => CURL_HTTP_VERSION_1_1,
    CURLOPT_CUSTOMREQUEST  => 'POST',
    CURLOPT_POSTFIELDS     => json_encode($postFields),
    CURLOPT_HTTPHEADER     => array(
        "Authorization: Bearer $accessToken",
        'Content-Type: application/json'
    ),
));

$response = curl_exec($curl);

curl_close($curl);
echo $response; // {"orderCode":4201736414972602}

?>

Get Support

If you would like to integrate with Viva, or if you have any queries about our products and solutions, please see our Contact & Support page to see how we can help!