Retrieve transaction

PHP code sample for retrieving a transaction.

Overview

The following PHP code sample includes comments explaining the different elements and parameters involved in the Retrieve transaction 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';
$transactionId = 'xxx';

$curl = curl_init();

curl_setopt_array($curl, array(
    CURLOPT_URL            => "https://demo-api.vivapayments.com/checkout/v2/transactions/$transactionId",
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_ENCODING       => '',
    CURLOPT_MAXREDIRS      => 10,
    CURLOPT_TIMEOUT        => 0,
    CURLOPT_FOLLOWLOCATION => true,
    CURLOPT_HTTP_VERSION   => CURL_HTTP_VERSION_1_1,
    CURLOPT_CUSTOMREQUEST  => 'GET',
    CURLOPT_HTTPHEADER     => array(
        "Authorization: Bearer $accessToken"
    ),
));

$response = curl_exec($curl);

curl_close($curl);
echo $response;

/*
{
    "email": "someone@vivawallet.com",
    "amount": 1,
    "orderCode": 6810910170372602,
    "statusId": "F",
    "fullName": "George Seferis",
    "insDate": "2021-12-13T11:16:32.541Z",
    "cardNumber": "523929XXXXXX0168",
    "currencyCode": 978,
    "customerTrns": "This is a description displayed to the customer",
    "merchantTrns": "This is a short description that helps you uniquely identify the transaction",
    "transactionTypeId": 5,
    "recurringSupport": true,
    "totalInstallments": 0,
    "cardUniqueReference": "9521B4209B611B11E080964E09640F4EB3C3AA18",
    "cardCountryCode": null,
    "cardIssuingBank": null,
    "currentInstallment": 0,
    "cardTypeId": 1
}
*/

?>

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!