forked from tpay-com/tpay-php
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CardGate.php
90 lines (77 loc) · 3.55 KB
/
CardGate.php
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<?php
/*
* Created by tpay.com
*/
namespace tpayLibs\examples;
use tpayLibs\src\_class_tpay\PaymentForms\PaymentCardForms;
use tpayLibs\src\_class_tpay\Utilities\Util;
use tpayLibs\src\Dictionaries\FieldsConfigDictionary;
include_once 'config.php';
include_once 'loader.php';
class CardGate extends PaymentCardForms
{
public function __construct()
{
//This is pre-configured sandbox access. You should use your own data in production mode.
$this->cardApiKey = 'bda5eda723bf1ae71a82e90a249803d3f852248d';
$this->cardApiPass = 'IhZVgraNcZoWPLgA';
$this->cardKeyRSA = 'LS0tLS1CRUdJTiBQVUJMSUMgS0VZLS0tLS0NCk1JR2ZNQTBHQ1NxR1NJYjNEUUVCQVFVQUE0R05BRENCaVFLQmdRQ2NLRTVZNU1Wemd5a1Z5ODNMS1NTTFlEMEVrU2xadTRVZm1STS8NCmM5L0NtMENuVDM2ekU0L2dMRzBSYzQwODRHNmIzU3l5NVpvZ1kwQXFOVU5vUEptUUZGVyswdXJacU8yNFRCQkxCcU10TTVYSllDaVQNCmVpNkx3RUIyNnpPOFZocW9SK0tiRS92K1l1YlFhNGQ0cWtHU0IzeHBhSUJncllrT2o0aFJDOXk0WXdJREFRQUINCi0tLS0tRU5EIFBVQkxJQyBLRVktLS0tLQ';
$this->cardVerificationCode = '6680181602d396e640cb091ea5418171';
$this->cardHashAlg = 'sha1';
parent::__construct();
}
public function init()
{
if (empty($_POST)) {
//Show new payment form
echo $this->getOnSiteCardForm('CardGate.php', true, false);
} else {
//Try to sale with provided card data
$response = $this->makeCardPayment();
//Successful payment by card not protected by 3DS
if (isset($response['result']) && (int)$response['result'] === 1) {
$this->setOrderAsComplete($response);
//Successfully generated 3DS link for payment authorization
} elseif (isset($response['3ds_url'])) {
header("Location: " . $response['3ds_url']);
} else {
//Invalid credit card data
$this->tryToSaleAgain();
}
}
}
private function makeCardPayment($failOver = false)
{
//If you set the third getOnSiteCardForm() parameter true, you can get client name and email here. Otherwise, you must get those values from your DB.
// $clientName = Util::post('client_name', FieldsConfigDictionary::STRING);
// $clientEmail = Util::post('client_email', FieldsConfigDictionary::STRING);
$clientEmail = 'customer@example.com';
$clientName = 'John Doe';
$cardData = Util::post('carddata', FieldsConfigDictionary::STRING);
$saveCard = Util::post('card_save', FieldsConfigDictionary::STRING);
Util::log('Secure Sale post params', print_r($_POST, true));
if ($saveCard === 'on') {
$this->setOneTimer(false);
}
$this->setAmount(123)->setCurrency(985)->setOrderID('test payment 123');
$this->setLanguage('en')->setReturnUrls('https://tpay.com', 'https://google.pl');
return $failOver === false ?
$this->registerSale($clientName, $clientEmail, 'test sale', $cardData) :
$this->setCardData(null)->registerSale($clientName, $clientEmail, 'test sale');
}
private function setOrderAsComplete($params)
{
var_dump($params);
}
private function tryToSaleAgain()
{
//Try to create new transaction and redirect customer to Tpay transaction panel
$response = $this->makeCardPayment(true);
if (isset($response['sale_auth'])) {
header("Location: " . 'https://secure.tpay.com/cards/?sale_auth=' . $response['sale_auth']);
} else {
echo $response['err_desc'];
}
}
}
(new CardGate())->init();