-
Notifications
You must be signed in to change notification settings - Fork 0
/
generateAndCharge.php
121 lines (112 loc) · 5.82 KB
/
generateAndCharge.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
<?php
require_once "lib.php";
require_once "authorize.php";
require_once 'vendor/autoload.php';
require_once "createPDF.php";
//die($PDFresp);
//die("RQ: " . print_r($_REQUEST, true));
$amount = calcPrice();// Config::$TRANSACTION_AMOUNT["AMOUNT_PAYCHECK"];
//die("CP: " . $amount);
$error = new stdClass();
$error->errorCode = 0;
$error->message = "Success";
$error->errorDescription ="Transaction completed successfully";
$error->transactionLog = array();
$error->PDFurl = "";
$error->transactionid = 0;
if(1==2) {
$filename = "dydy.pdf";//time() . ".pdf";
$PDFresp = createPDF(Config::$PDF_LOCATION . "/$filename", "F", request("design"));
$error->PDFurl = $PDFresp;
$error->errorCode = 1;
} else
{
writeLog("R: " . print_r($_REQUEST, true));
writeLog("AUTHORIZING TRANSACTION: " . print_r(array($amount, str_replace("-", "", request("cardNumber")), "20" . request("date"), request("cvc")
, request("pfirstname"), request("plastname"), request("street"), request("city"), request("state"), request("zip")
, request("country"), request("email")), Config::LOG_LEVEL_INFO), true);
$e = authorizeCreditCard($amount, str_replace("-", "", request("cardNumber")), "20" . request("date"), request("cvc")
, request("pfirstname"), request("plastname"), request("street"), request("city"), request("state"), request("zip")
, request("country"), request("email"));
writeLog("AUTHORIZE RESULT: " . print_r($e, true), Config::LOG_LEVEL_INFO);
if($e->getTransactionResponse())
{
$id = $e->getTransactionResponse()->getTransId();
$error->transactionid = $id;
if($e->getTransactionResponse()->getMessages()) {
$code = $e->getTransactionResponse()->getMessages()[0]->getCode();
$error->message = $e->getTransactionResponse()->getMessages()[0]->getDescription() . " ";
$error->transactionLog[] = "AUTHORIZE: " . $e->getTransactionResponse()->getMessages()[0]->getCode() . " " . $e->getTransactionResponse()->getMessages()[0]->getDescription();
}
$msgCode = $e->getMessages()->getMessage()[0]->getCode();
$errors = count($e->getTransactionResponse()->getErrors());
if($errors > 0)
{
$error->message = "TRANSACTION ID: $id DECLINED ";
$error->errorCode = $e->getTransactionResponse()->getErrors()[0]->getErrorCode();
$error->errorDescription = $e->getTransactionResponse()->getErrors()[0]->getErrorText();
}
writeLog("A: $id /MC $msgCode /EC $errors /C $code");
if($e->getMessages()->getMessage()[0]->getCode() == "I00001" && $errors == 0 && $code == 1) {
$filename = time() . ".pdf";
$PDFresp = createPDF(Config::$PDF_LOCATION . "/$filename");
if($PDFresp) {
writeLog("CAPTURING TRANSACTION $id:");
$ec = capturePreviouslyAuthorizedAmount($id);
writeLog("CAPTURE $id RESULT: " . print_r($ec, true));
if($ec->getTransactionResponse()->getMessages()) {
$code = $ec->getTransactionResponse()->getMessages()[0]->getCode();
$error->message = $ec->getTransactionResponse()->getMessages()[0]->getDescription();
$error->transactionLog[] = "CAPTURE: " . $ec->getTransactionResponse()->getMessages()[0]->getCode() . " " . $ec->getTransactionResponse()->getMessages()[0]->getDescription();
}
$msgCode = $ec->getMessages()->getMessage()[0]->getCode();
$errors = count($ec->getTransactionResponse()->getErrors());
if($errors > 0)
{
$error->message = "TRANSACTION ID: $id DECLINED";
$error->errorCode = $ec->getTransactionResponse()->getErrors()[0]->getErrorCode();
$error->errorDescription = $ec->getTransactionResponse()->getErrors()[0]->getErrorText();
}
$error->PDFurl = $PDFresp; //"http;//http://realpaystubdownload.com/$filename";
writeLog("CR: $id /MC $msgCode /EC $errors /C $code");
} else {
writeLog("VOIDING TRANSACTION $id:");
$ec = voidTransaction($id);
writeLog("VOID $id RESULT: " . print_r($ec, true));
$error->description = "PDF generating problem";
if($ec->getTransactionResponse()->getMessages()) {
$code = $ec->getTransactionResponse()->getMessages()[0]->getCode();
$error->message = $ec->getTransactionResponse()->getMessages()[0]->getDescription();
$error->transactionLog[] = "VOID: " . $ec->getTransactionResponse()->getMessages()[0]->getCode() . " " . $ec->getTransactionResponse()->getMessages()[0]->getDescription();
}
$msgCode = $ec->getMessages()->getMessage()[0]->getCode();
$errors = count($ec->getTransactionResponse()->getErrors());
if($errors > 0)
{
//$error->message = "TRANSACTION ID: $id DECLINED";
$error->errorCode = $ec->getTransactionResponse()->getErrors()[0]->getErrorCode();
$error->message = $ec->getTransactionResponse()->getErrors()[0]->getErrorText();
}
writeLog("VR: $id /MC $msgCode /EC $errors /C $code");
}
} else if($code == "E00007") {
$error->message = "TRANSACTION ID: $id DECLINED";
$error->errorDescription = $e->getMessages()->getMessage()[0]->getText();
$error->errorCode = $code;
} else {
$error->message = "TRANSACTION ID: $id DECLINED";
$error->errorDescription = $e->getMessages()->getMessage()[0]->getText();
$error->errorCode = $code;
}
writeLog("RETURNED MESSAGE: " . print_r($error, true));
} else {
//echo "E: " . die(print_r($e->getMessages()->getMessage()[0], true));
$error->message = "TRANSACTION ID: $id DECLINED";
$error->errorCode = $e->getMessages()->getMessage()[0]->getCode();
if($error->errorCode == "E00003") {
$error->errorDescription = "Card number, expiration date or CVC is invalid. The actual length is less than the Min Length value.";
}
}
}
header('Content-Type: application/json');
echo json_encode($error);