PHP code example of twikey / twikey-api-php

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

    

twikey / twikey-api-php example snippets


use GuzzleHttp\Client;
use GuzzleHttp\ClientInterface;
use Twikey\Api;

$httpClient = new Client([
    'http_errors' => false,
    'debug' => false
]);

$twikey = new Twikey($httpClient,$APIKEY);

$invite = $twikey->document->create([
    "ct" => $ct
    "email" => "[email protected]",
    "firstname" => "John",
    "lastname" => "Doe",
]);

// store $invite->mndtId for this customer
header("Location: " . $invite->url);
 
$twikey->document->feed(new class implements DocumentCallback {
   function handleNew($update)
   {
       print("New " . $update->Mndt->MndtId . ' @ '. $update->EvtTime . "\n");
   }

   function handleUpdate($update)
   {
       $rsn = $update->AmdmntRsn->Rsn;
       print("Update: " . $update->Mndt->MndtId . ' -> '. $rsn . ' @ '. $update->EvtTime . "\n");
   }

   function handleCancel($update)
   {
       $rsn = $update->CxlRsn->Rsn;
       print("Cancel: " . $update->OrgnlMndtId . ' -> '. $rsn . ' @ '. $update->EvtTime . "\n");
   }
}
);

$invite = $twikey->transaction->create([
   "mndtId" => "CORERECURRENTNL16318",
   "message" => "Test Message",
   "ref" => "Merchant Reference",
   "amount" => 10.00, // 10 euro
   "place" => "Here"
]);
 
$count = $twikey->transaction->feed(new class implements TransactionCallback{
   public function handle($transaction)
   {
       print("Transaction " . $transaction->id . ' @ '. $transaction->date . ' has '. $transaction->state . "\n");
   }
});

$queryString = decode($_SERVER['QUERY_STRING']);
$signatureHeader = $_SERVER['HTTP_X_SIGNATURE'];

Twikey::validateWebhook($APIKEY, "abc=123&name=abc", $queryString, $signatureHeader);