|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
|
|
4
|
|
|
class EcommercePayment_Stripe_CustomerDetails extends DataExtension |
|
|
|
|
|
|
5
|
|
|
{ |
|
6
|
|
|
private static $db = array( |
|
|
|
|
|
|
7
|
|
|
"StripeCustomerID" => "Varchar(32)", |
|
8
|
|
|
"CreditCardDescription" => "Varchar(64)" |
|
9
|
|
|
); |
|
10
|
|
|
|
|
11
|
|
|
private static $indexes = array( |
|
|
|
|
|
|
12
|
|
|
"StripeCustomerID" => true |
|
13
|
|
|
); |
|
14
|
|
|
|
|
15
|
|
|
private static $casting = array( |
|
|
|
|
|
|
16
|
|
|
"CreditCardHasBeenRecorded" => "boolean" |
|
17
|
|
|
); |
|
18
|
|
|
|
|
19
|
|
|
private static $field_labels = array( |
|
|
|
|
|
|
20
|
|
|
"StripeCustomerID" => "Customer ID for Stripe Payments", |
|
21
|
|
|
"CreditCardDescription" => "Credit Card Description", |
|
22
|
|
|
"CreditCardHasBeenRecorded" => "Credit Card on File" |
|
23
|
|
|
); |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* |
|
27
|
|
|
* @return Boolean |
|
28
|
|
|
*/ |
|
29
|
|
|
public function CreditCardHasBeenRecorded() |
|
30
|
|
|
{ |
|
31
|
|
|
return $this->getCreditCardHasBeenRecorded(); |
|
32
|
|
|
} |
|
33
|
|
|
public function getCreditCardHasBeenRecorded() |
|
34
|
|
|
{ |
|
35
|
|
|
return $this->owner->StripeCustomerID ? true : false; |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
|
|
39
|
|
|
public function updateCMSFields(FieldList $fields) |
|
40
|
|
|
{ |
|
41
|
|
|
$fieldLabels = $this->owner->FieldLabels(); |
|
42
|
|
|
$fields->addFieldToTab( |
|
43
|
|
|
"Root.StripePayments", |
|
44
|
|
|
ReadonlyField::create("CreditCardHasBeenRecordedNice", $fieldLabels["CreditCardHasBeenRecorded"], $this->owner->obj("CreditCardHasBeenRecorded")->nice()) |
|
45
|
|
|
); |
|
46
|
|
|
if ($this->owner->StripeCustomerID) { |
|
47
|
|
|
$dropdownArray = array( |
|
48
|
|
|
$this->owner->StripeCustomerID => $this->owner->CreditCardDescription, |
|
49
|
|
|
null => _t("EcommercePayment_Stripe_CustomerDetails.REMOVE_CARD", "- REMOVE CARD -") |
|
50
|
|
|
); |
|
51
|
|
|
$fields->addFieldToTab( |
|
52
|
|
|
"Root.StripePayments", |
|
53
|
|
|
DropdownField::create("StripeCustomerID", $fieldLabels["CreditCardDescription"], $dropdownArray) |
|
54
|
|
|
); |
|
55
|
|
|
} |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
public function augmentEcommerceFields($fields) |
|
59
|
|
|
{ |
|
60
|
|
|
$fieldLabels = $this->owner->FieldLabels(); |
|
61
|
|
|
$fields->push( |
|
62
|
|
|
ReadonlyField::create("CreditCardHasBeenRecordedNice", $fieldLabels["CreditCardHasBeenRecorded"], $this->owner->obj("CreditCardHasBeenRecorded")->nice()) |
|
63
|
|
|
); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
public function onBeforeWrite() |
|
67
|
|
|
{ |
|
68
|
|
|
if (!$this->owner->StripeCustomerID) { |
|
69
|
|
|
$this->owner->CreditCardDescription = null; |
|
70
|
|
|
} |
|
71
|
|
|
} |
|
72
|
|
|
} |
|
73
|
|
|
|
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.