This repository was archived by the owner on Oct 5, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathOrder.php
More file actions
executable file
·132 lines (121 loc) · 5.13 KB
/
Copy pathOrder.php
File metadata and controls
executable file
·132 lines (121 loc) · 5.13 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
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
122
123
124
125
126
127
128
129
130
131
132
<?php
namespace Worldpay;
define("ORDER_TYPES", serialize(array("ECOM", "MOTO", "RECURRING")));
class Order extends AbstractOrder
{
protected $orderType;
protected $is3DSOrder;
protected $authorizeOnly;
protected $redirectURL;
public function __construct($order)
{
Order::validateInputData($order);
$order = array_merge(self::getOrderDefaults(), $order);
$this->orderType = in_array($order['orderType'], unserialize(ORDER_TYPES)) ? $order['orderType'] : 'ECOM';
$this->redirectURL = false;
$this->orderDescription = $order['orderDescription'];
$this->amount = $order['amount'];
$this->is3DSOrder = $order['is3DSOrder'] ? true : false;
$this->currencyCode = $order['currencyCode'];
$this->name = $order['name'];
$this->shopperEmailAddress = $order['shopperEmailAddress'];
$this->authorizeOnly = isset($order['authorizeOnly']) && $order['authorizeOnly']
|| isset($order['authoriseOnly']) && $order['authoriseOnly']
? true : false;
$this->billingAddress = new BillingAddress($order['billingAddress']);
$this->deliveryAddress = new DeliveryAddress($order['deliveryAddress']);
$this->customerOrderCode = $order['customerOrderCode'];
$this->orderCodePrefix = $order['orderCodePrefix'];
$this->orderCodeSuffix = $order['orderCodeSuffix'];
$this->paymentMethod = self::extractPaymentMethodFromData($order);
if ($this->isDirectOrder()) {
$this->reusable = $order['reusable'];
$this->shopperLanguageCode = $order['shopperLanguageCode'];
} else {
$this->token = $order['token'];
unset($this->paymentMethod);
}
if ($this->is3DSOrder) {
$_SESSION['worldpay_sessionid'] = uniqid();
$threeDSShopper = Utils::getThreeDSShopperObject();
$this->shopperIpAddress = $threeDSShopper['shopperIpAddress'];
$this->shopperSessionId = $threeDSShopper['shopperSessionId'];
$this->shopperUserAgent = $threeDSShopper['shopperUserAgent'];
$this->shopperAcceptHeader = $threeDSShopper['shopperAcceptHeader'];
}
if (isset($order['shopperIpAddress'])) {
$this->shopperIpAddress = $order['shopperIpAddress'];
}
if (isset($order['shopperSessionId'])) {
$this->shopperSessionId = $order['shopperSessionId'];
}
if (isset($order['shopperUserAgent'])) {
$this->shopperUserAgent = $order['shopperUserAgent'];
}
if (isset($order['shopperAcceptHeader'])) {
$this->shopperAcceptHeader = $order['shopperAcceptHeader'];
}
if (isset($order['siteCode'])) {
$this->siteCode = $order['siteCode'];
}
if (isset($order['statementNarrative'])) {
$this->statementNarrative = $order['statementNarrative'];
}
if (!empty($order['settlementCurrency'])) {
$this->settlementCurrency = $order['settlementCurrency'];
}
if (!empty($order['customerIdentifiers'])) {
$this->customerIdentifiers = $order['customerIdentifiers'];
}
}
private static function extractPaymentMethodFromData($data)
{
$paymentMethod = array();
if (isset($data['paymentMethod'])) {
$_orderPM = $data['paymentMethod'];
if($_orderPM['type'] === "CSE"){
$paymentMethod = array(
'type' =>$_orderPM['type'],
'encryptedData' =>$_orderPM['encryptedData']
);
}else {
$_name = isset($_orderPM['name']) ? $_orderPM['name'] : "";
$_expiryMonth = isset($_orderPM['expiryMonth']) ? $_orderPM['expiryMonth'] : "";
$_expiryYear = isset($_orderPM['expiryYear']) ? $_orderPM['expiryYear'] : "";
$_cardNumber = isset($_orderPM['cardNumber']) ? $_orderPM['cardNumber'] : "";
$_cvc = isset($_orderPM['cvc']) ? $_orderPM['cvc'] : "";
$paymentMethod = array(
"type" => "Card",
"name" => $_name,
"expiryMonth" => $_expiryMonth,
"expiryYear" => $_expiryYear,
"cardNumber" => $_cardNumber,
"cvc" => $_cvc,
);
}
}
return $paymentMethod;
}
private static function getOrderDefaults()
{
$defaults = array(
'orderType' => 'ECOM',
'name' => null,
'billingAddress' => null,
'reusable' => false,
'shopperLanguageCode' => "",
'deliveryAddress' => null,
'isDirectOrder' => false,
'is3DSOrder' => false,
'authorizeOnly' => false,
'redirectURL' => false,
'currencyCode' => null,
'shopperEmailAddress' => null,
'orderCodePrefix' => null,
'orderCodeSuffix' => null,
'customerOrderCode' => null,
'paymentMethod' => null
);
return $defaults;
}
}