|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
class DpsPxPayStoredPayment_Handler extends DpsPxPayPayment_Handler |
|
|
|
|
|
|
4
|
|
|
{ |
|
5
|
|
|
private static $url_segment = 'dpspxpaystoredpayment'; |
|
|
|
|
|
|
6
|
|
|
|
|
7
|
|
|
|
|
8
|
|
|
public static function complete_link() |
|
9
|
|
|
{ |
|
10
|
|
|
return Config::inst()->get('DpsPxPayStoredPayment_Handler', 'url_segment') . '/paid/'; |
|
11
|
|
|
} |
|
12
|
|
|
|
|
13
|
|
|
public static function absolute_complete_link() |
|
14
|
|
|
{ |
|
15
|
|
|
return Director::AbsoluteURL(self::complete_link()); |
|
16
|
|
|
} |
|
17
|
|
|
|
|
18
|
|
|
public function paid() |
|
19
|
|
|
{ |
|
20
|
|
|
$commsObject = new DpsPxPayComs(); |
|
21
|
|
|
$response = $commsObject->processRequestAndReturnResultsAsObject(); |
|
22
|
|
|
if ($payment = DpsPxPayStoredPayment::get()->byID($response->getMerchantReference())) { |
|
23
|
|
|
if ($payment->Status != 'Success') { |
|
24
|
|
|
if (1 == $response->getSuccess()) { |
|
25
|
|
|
$payment->Status = 'Success'; |
|
26
|
|
|
|
|
27
|
|
|
if ($response->DpsBillingId) { |
|
28
|
|
|
$existingCard = DpsPxPayStoredCard::get()->filter(array("BillingID" => $response->DpsBillingId))->First(); |
|
29
|
|
|
|
|
30
|
|
|
if ($existingCard == false) { |
|
31
|
|
|
$storedCard = new DpsPxPayStoredCard(); |
|
32
|
|
|
$storedCard->BillingID = $response->DpsBillingId; |
|
|
|
|
|
|
33
|
|
|
$storedCard->CardName = $response->CardName; |
|
|
|
|
|
|
34
|
|
|
$storedCard->CardHolder = $response->CardHolderName; |
|
|
|
|
|
|
35
|
|
|
$storedCard->CardNumber = $response->CardNumber; |
|
|
|
|
|
|
36
|
|
|
$storedCard->MemberID = $payment->Order()->MemberID; |
|
|
|
|
|
|
37
|
|
|
$storedCard->write(); |
|
38
|
|
|
} |
|
39
|
|
|
} |
|
40
|
|
|
} else { |
|
41
|
|
|
$payment->Status = 'Failure'; |
|
42
|
|
|
} |
|
43
|
|
|
if ($DpsTxnRef = $response->getDpsTxnRef()) { |
|
44
|
|
|
$payment->TxnRef = $DpsTxnRef; |
|
45
|
|
|
} |
|
46
|
|
|
if ($ResponseText = $response->getResponseText()) { |
|
47
|
|
|
$payment->Message = $ResponseText; |
|
48
|
|
|
} |
|
49
|
|
|
$payment->write(); |
|
50
|
|
|
} |
|
51
|
|
|
$payment->redirectToOrder(); |
|
52
|
|
|
} else { |
|
53
|
|
|
USER_ERROR("could not find payment with matching ID", E_USER_WARNING); |
|
54
|
|
|
} |
|
55
|
|
|
return; |
|
56
|
|
|
} |
|
57
|
|
|
} |
|
58
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.