-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathPayTech.php
More file actions
59 lines (53 loc) · 1.91 KB
/
PayTech.php
File metadata and controls
59 lines (53 loc) · 1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?php
namespace PayTech;
use PayTech\Invoice\InvoiceItem;
use PayTech\Utils\MakeRequest;
/**
*
* @author PapiHack
* @since 07/2020
*
*/
abstract class PayTech
{
const VERSION = "1.0.3";
const VERSION_NAME = "PayTech PHP SDK Client v1 aka Naruto";
public static function send(InvoiceItem $invoiceItem)
{
$response = MakeRequest::post(Config::ROOT_URL_BASE . Config::PAYMENT_REQUEST_PATH, [
'item_name' => $invoiceItem->getName(),
'item_price' => $invoiceItem->getPrice(),
'command_name' => $invoiceItem->getCommandName(),
'ref_command' => $invoiceItem->getRefCommand(),
'env' => Config::getEnv(),
'currency' => Config::getCurrency(),
'ipn_url' => Config::getIpnUrl(),
'success_url' => Config::getIsMobile() ? Config::MOBILE_SUCCESS_URL : Config::getSuccessUrl(),
'cancel_url' => Config::getIsMobile() ? Config::MOBILE_CANCEL_URL : Config::getCancelUrl(),
'custom_field' => CustomField::retrieve()->toJSONString()
], []);
// @codeCoverageIgnoreStart
if (array_key_exists('token', $response))
{
ApiResponse::setSuccess(1);
ApiResponse::setToken($response['token']);
ApiResponse::setRedirectUrl(Config::ROOT_URL_BASE . Config::PAYMENT_REDIRECT_PATH . $response['token']);
}
else if(array_key_exists('error', $response))
{
ApiResponse::setSuccess(-1);
ApiResponse::setErrors($response['error']);
}
else if(array_key_exists('message', $response))
{
ApiResponse::setSuccess(-1);
ApiResponse::setErrors($response['message']);
}
else
{
ApiResponse::setSuccess(-1);
ApiResponse::setErrors(['Internal Error']);
}
// @codeCoverageIgnoreEnd
}
}