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 pathAPMOrder.php
More file actions
executable file
·95 lines (85 loc) · 3.33 KB
/
Copy pathAPMOrder.php
File metadata and controls
executable file
·95 lines (85 loc) · 3.33 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
<?php
namespace Worldpay;
class APMOrder extends AbstractOrder
{
protected $successUrl;
protected $pendingUrl;
protected $failureUrl;
protected $cancelUrl;
public function __construct($order)
{
Order::validateInputData($order);
$order = array_merge(self::getOrderDefaults(), $order);
$this->orderDescription = $order['orderDescription'];
$this->amount = $order['amount'];
$this->currencyCode = $order['currencyCode'];
$this->name = $order['name'];
$this->shopperEmailAddress = $order['shopperEmailAddress'];
$this->billingAddress = new BillingAddress($order['billingAddress']);
$this->deliveryAddress = new DeliveryAddress($order['deliveryAddress']);
$this->customerOrderCode = $order['customerOrderCode'];
$this->successUrl = $order['successUrl'];
$this->pendingUrl = $order['pendingUrl'];
$this->failureUrl = $order['failureUrl'];
$this->cancelUrl = $order['cancelUrl'];
$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 (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'];
$_apmName = isset($_orderPM['apmName']) ? $_orderPM['apmName'] : "";
$_shopperCountryCode = isset($_orderPM['shopperCountryCode']) ? $_orderPM['shopperCountryCode'] : "";
$_apmFields = isset($_orderPM['apmFields']) ? $_orderPM['apmFields'] : new stdClass();
$paymentMethod = array(
"type" => "APM",
"apmName" => $_apmName,
"shopperCountryCode" => $_shopperCountryCode,
"apmFields" => $_apmFields
);
}
return $paymentMethod;
}
private static function getOrderDefaults()
{
$defaults = array(
'name' => null,
'amount' => null,
'reusable' => false,
'orderDescription' => null,
'shopperLanguageCode' => "",
'customerOrderCode' => null,
'currencyCode' => null,
'deliveryAddress' => null,
'billingAddress' => null,
'successUrl' => null,
'pendingUrl' => null,
'failureUrl' => null,
'cancelUrl' => null,
'shopperEmailAddress' => null,
'orderCodePrefix' => null,
'orderCodeSuffix' => null,
'paymentMethod' => null
);
return $defaults;
}
}