<?php
/*
Copyright (c) 2009 hamcrest.org
*/
abstract class FactoryFile
{
/**
* Hamcrest standard is two spaces for each level of indentation.
*
* @var string
*/
const INDENT = ' ';
private $indent;
private $file;
private $code;
public function __construct($file, $indent)
{
$this->file = $file;
$this->indent = $indent;
}
abstract public function addCall(FactoryCall $call);
abstract public function build();
public function addFileHeader()
{
$this->code = '';
$this->addPart('file_header');
}
public function addPart($name)
{
$this->addCode($this->readPart($name));
}
public function addCode($code)
{
$this->code .= $code;
}
public function readPart($name)
{
return file_get_contents(__DIR__ . "/parts/$name.txt");
}
public function generateFactoryCall(FactoryCall $call)
{
$method = $call->getMethod();
$code = $method->getComment($this->indent) . "\n";
$code .= $this->generateDeclaration($call->getName(), $method);
$code .= $this->generateCall($method);
$code .= $this->generateClosing();
return $code;
}
public function generateDeclaration($name, FactoryMethod $method)
{
$code = $this->indent . $this->getDeclarationModifiers()
. 'function ' . $name . '('
. $this->generateDeclarationArguments($method)
. ')' . "\n" . $this->indent . '{' . "\n";
return $code;
}
public function getDeclarationModifiers()
{
return '';
}
public function generateDeclarationArguments(FactoryMethod $method)
{
if ($method->acceptsVariableArguments()) {
return '/* args... */';
} else {
return $method->getParameterDeclarations();
}
}
public function generateImport(FactoryMethod $method)
{
return $this->indent . self::INDENT . "require_once '" . $method->getClass()->getFile() . "';" . "\n";
}
public function generateCall(FactoryMethod $method)
{
$code = '';
if ($method->acceptsVariableArguments()) {
$code .= $this->indent . self::INDENT . '$args = func_get_args();' . "\n";
}
$code .= $this->indent . self::INDENT . 'return ';
if ($method->acceptsVariableArguments()) {
$code .= 'call_user_func_array(array(\''
. '\\' . $method->getClassName() . '\', \''
. $method->getName() . '\'), $args);' . "\n";
} else {
$code .= '\\' . $method->getClassName() . '::'
. $method->getName() . '('
. $method->getParameterInvocations() . ');' . "\n";
}
return $code;
}
public function generateClosing()
{
return $this->indent . '}' . "\n";
}
public function write()
{
file_put_contents($this->file, $this->code);
}
}
Initiates a new payment transaction.
create-order
| Parameter | Type | Details |
|---|---|---|
| amount | decimal | Your Amount , Must be rounded at 2 precision. |
| currency | string | Currency Code, Must be in Upper Case (Alpha-3 code) |
| success_url | string | Enter your return or success URL |
| cancel_url | string (optional) | Enter your cancel or failed URL |
Request Example (guzzle)
<?php
require_once('vendor/autoload.php');
$client = new \GuzzleHttp\Client();
$response = $client->request('POST', $base_url.'create-order', [
'headers' => [
'Authorization' => 'Bearer '. $authorizationToken,
'accept' => 'application/json',
'content-type' => 'application/json',
],
'form_params' => [
'amount' => '$amount',
'currency' => 'currency',
'success_url' => 'success_url',
'cancel_url' => 'cancel_url',
],
]);
echo $response->getBody();
**Response: SUCCESS (200 OK)**
{
"message": {
"success": [
"Order created successfully."
]
},
"data": {
"redirect_url":"https://example.com/login/OISADFDFSDFSF",
"order_details":{
"amount" : "10",
"fixed_charge" : 2,
"percent_charge" : 1,
"total_charge" : 3,
"total_payable" : 13,
"currency" : "USD",
"expiry_time": "2024-04-25T06:48:35.984285Z",
"success_url": "http://127.0.0.1/nfcpay/user/transaction/success",
"cancel_url": "http://127.0.0.1/nfcpay/user/transaction/cancel"
}
},
"type": "success"
}
**Response: ERROR (400 FAILED)**
{
"message": {
"error": [
"Invalid token."
]
},
"data": null,
"type": "error"
}