1. Go to this page and download the library: Download stadem/viva-payments library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
use Stadem\VivaPayments\Enums;
use Stadem\VivaPayments\Services\AccessToken;
use Stadem\VivaPayments\Request\Customer;
use Stadem\VivaPayments\Request\CreatePaymentOrder;
$requestLang = $_REQUEST['requestLang'] ?? 'Greek';
$config = new Config();
$accessToken = new AccessToken($config);
$customer = new Customer(
$email = '[email protected]',
$fullName = 'Customer name',
$phone = '+306941234567',
$countryCode = 'GR',
$requestLang = Enums\RequestLang::fromName($requestLang),
);
$CreatePaymentOrder = [
'amount' => 120,
'customerTrns' => 'Test POST - No End Payment', items/services being purchased.
'paymentTimeout' => 1800,
'preauth' => false,
'allowRecurring' => false,
'maxInstallments' => 0,
'forceMaxInstallments' => false,
'paymentNotification' => true,
'tipAmount' => 0,
'disableExactAmount' => false,
'disableCash' => true,
'disableWallet' => false,
'cardTokens' => null, Tokens tutorial.
'merchantTrns' => 'This is a short description that helps you uniquely identify the transaction',
'tags' => ['tag1', 'tag2']
];
$paymentMethods = [0, 8, 21, 29, 34, 35];
$paymentMethodFees = [
'paymentMethodId' => '35',
'fee' => 550
];
try {
$order = new CreatePaymentOrder($CreatePaymentOrder, $accessToken,$config);
$order->setCustomer($customer);
$order->setPaymentMethods($paymentMethods);
$order->setPaymentMethodsFees($paymentMethodFees);
$getOrderJson = $order->send();
echo '<a href="' . $order->redirectUrl(PaymentMethods: Enums\PaymentMethods::fromName('VivaWallet')) . '" target="blank">';
echo $order->getOrderCode();
echo '</a>';
} catch (Exception $e) {
echo 'An error occured: <b>' . $e->getMessage() . '</b>';
}
use Stadem\VivaPayments\Enums;
use Stadem\VivaPayments\Services\AccessToken;
use Stadem\VivaPayments\Request\Customer;
use Stadem\VivaPayments\Request\CreatePaymentOrder;
use Stadem\VivaPayments\Config\Config;
$config = new Config();
$accessToken = new AccessToken(); // Set the value on config file -> defaultProvider
or
$config = new Config();
$accessToken = new AccessToken(environment: 'vivaDEMO'); // By direct set, mostly for testing purposes