PHP code example of gr4vy / gr4vy-php

1. Go to this page and download the library: Download gr4vy/gr4vy-php 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/ */

    

gr4vy / gr4vy-php example snippets



vateKeyLocation = __DIR__ . "/private_key.pem";

$config = new Gr4vy\Gr4vyConfig("[YOUR_GR4VY_ID]", $privateKeyLocation);

try {
    $result = $config->listBuyers();
    print_r($result);
} catch (Exception $e) {
    echo 'Exception when calling listBuyers: ', $e->getMessage(), PHP_EOL;
}


$config = new Gr4vy\Gr4vyConfig("[YOUR_GR4VY_ID]", $privateKeyLocation, false, "sandbox");

$config = new Gr4vy\Gr4vyConfig("[YOUR_GR4VY_ID]", $privateKeyLocation, false, "production");


//A checkout session allows multiple transaction attempts to be tied together
$checkoutSession = $config->newCheckoutSession();

echo $config->getEmbedToken(
  array(
    "amount"=> 200,
    "currency" => "USD",
    "buyer_id"=> "d757c76a-cbd7-4b56-95a3-40125b51b29c"
  ), 
  $checkoutSession["id"]
);

echo $config->getEmbedTokenWithCheckoutSession(
  array(
    "amount"=> 200,
    "currency" => "USD",
    "buyer_id"=> "d757c76a-cbd7-4b56-95a3-40125b51b29c"
  )
);

$config = new Gr4vy\Gr4vyConfig("[YOUR_GR4VY_ID]", $privateKeyLocation);

$buyer_request = array("external_identifier"=>"412231123","display_name"=>"Tester T.");
$buyer = $config->addBuyer($buyer_request);

$embed = array("amount"=> 200, "currency" => "USD", "buyer_id"=> $buyer["id"]);
$embedToken = $config->getEmbedToken($embed);

$config->getEmbedToken(
  array(
    "amount"=> 200,
    "currency" => "USD",
    "buyer_id"=> "d757c76a-cbd7-4b56-95a3-40125b51b29c"
  ), 
  $storedCheckoutSessionId
);

$config = new Gr4vy\Gr4vyConfig("acme", $privateKeyLocation);

$config = new Gr4vy\Gr4vyConfig("acme", $privateKeyLocation);
$config->setHost("https://api.acme.gr4vy.app");

$config = new Gr4vy\Gr4vyConfig("[YOUR_GR4VY_ID]", $privateKeyLocation, false, "sandbox", "default");

$config = new Gr4vy\Gr4vyConfig("[YOUR_GR4VY_ID]", $privateKeyLocation, false, "sandbox", "my_merchant_account_id");

$result = $config->listBuyers(100);

$buyer_request = array("external_identifier"=>"412231123","display_name"=>"Tester T.");
$buyer = $config->addBuyer($buyer_request);

$buyer_update = array("external_identifier"=>"testUpdateBuyer");
$result = $config->updateBuyer($result["id"], $buyer_update);

$bearerToken = Gr4vyConfig::getToken($privateKeyLocation, array("*.read", "*.write"))->toString();
ini
Authorization: Bearer <bearerToken>