|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* "Abstract" class for a number of different payment |
|
4
|
|
|
* types allowing a user to pay for something on a site. |
|
5
|
|
|
* |
|
6
|
|
|
* |
|
7
|
|
|
* This can't be an abstract class because sapphire doesn't |
|
8
|
|
|
* support abstract DataObject classes. |
|
9
|
|
|
* |
|
10
|
|
|
* @package payment |
|
11
|
|
|
*/ |
|
12
|
|
|
class EcommercePayment_Stripe_ChargeRecordedCustomer extends EcommercePayment_Stripe |
|
|
|
|
|
|
13
|
|
|
{ |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Perform payment processing for the type of |
|
17
|
|
|
* payment. For example, if this was a credit card |
|
18
|
|
|
* payment type, you would perform the data send |
|
19
|
|
|
* off to the payment gateway on this function for |
|
20
|
|
|
* your payment subclass. |
|
21
|
|
|
* |
|
22
|
|
|
* This is used by {@link OrderForm} when it is |
|
23
|
|
|
* submitted. |
|
24
|
|
|
* |
|
25
|
|
|
* @param array $data The form request data - see OrderForm |
|
26
|
|
|
* @param OrderForm $form The form object submitted on |
|
27
|
|
|
* |
|
28
|
|
|
* @return EcommercePaymentResult |
|
|
|
|
|
|
29
|
|
|
*/ |
|
30
|
|
View Code Duplication |
public function processPayment($data, $form) |
|
|
|
|
|
|
31
|
|
|
{ |
|
32
|
|
|
//get variables |
|
33
|
|
|
$responseData = null; |
|
34
|
|
|
//get variables |
|
35
|
|
|
$this->retrieveVariables(); |
|
36
|
|
|
$this->instantiateAPI(); |
|
37
|
|
|
//less than fifty cents then it is fine ... |
|
38
|
|
|
if ($this->_processing_amount < 50) { |
|
39
|
|
|
$this->Status = "Success"; |
|
|
|
|
|
|
40
|
|
|
$returnObject = EcommercePayment_Success::create(); |
|
|
|
|
|
|
41
|
|
|
} elseif ($this->_processing_member && $this->_processing_member->CreditCardHasBeenRecorded()) { |
|
|
|
|
|
|
42
|
|
|
//if currency has been pre-set use this |
|
43
|
|
|
$requestData = array( |
|
44
|
|
|
'customer' => $this->_processing_member->StripeCustomerID, |
|
|
|
|
|
|
45
|
|
|
'amount' => $this->_processing_amount, |
|
46
|
|
|
'currency' => $this->_processing_currency, |
|
47
|
|
|
'capture' => true, |
|
48
|
|
|
'statement_descriptor' => $this->_processing_statement_description, |
|
49
|
|
|
'metadata' => $this->_processing_metadata |
|
50
|
|
|
); |
|
51
|
|
|
$responseData = \Stripe\Charge::create($requestData, $this->_processing_idempotency_key); |
|
|
|
|
|
|
52
|
|
|
$this->removeCardDetails(); |
|
53
|
|
|
|
|
54
|
|
|
//save basic info |
|
55
|
|
|
$this->recordTransaction($requestData, $responseData); |
|
56
|
|
|
|
|
57
|
|
|
//no idea why we need this!!! |
|
58
|
|
|
$this->Amount->Amount = $this->_processing_amount / 100; |
|
|
|
|
|
|
59
|
|
|
} |
|
60
|
|
|
if ( |
|
61
|
|
|
$responseData && |
|
62
|
|
|
$responseData->status == "succeeded" |
|
63
|
|
|
) { |
|
64
|
|
|
$this->Status = "Success"; |
|
|
|
|
|
|
65
|
|
|
$returnObject = EcommercePayment_Success::create(); |
|
66
|
|
|
} else { |
|
67
|
|
|
$this->Status = "Failure"; |
|
|
|
|
|
|
68
|
|
|
$returnObject = EcommercePayment_Failure::create(); |
|
69
|
|
|
} |
|
70
|
|
|
$this->write(); |
|
71
|
|
|
return $returnObject; |
|
72
|
|
|
} |
|
73
|
|
|
} |
|
74
|
|
|
|
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.