updateCMSFields()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 18
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 18
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 12
nc 2
nop 1
1
<?php
2
3
4
class EcommercePayment_Stripe_CustomerDetails extends DataExtension
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
5
{
6
    private static $db = array(
0 ignored issues
show
Unused Code introduced by
The property $db is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
7
        "StripeCustomerID" => "Varchar(32)",
8
        "CreditCardDescription" => "Varchar(64)"
9
    );
10
11
    private static $indexes = array(
0 ignored issues
show
Unused Code introduced by
The property $indexes is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
12
        "StripeCustomerID" => true
13
    );
14
15
    private static $casting = array(
0 ignored issues
show
Unused Code introduced by
The property $casting is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
16
        "CreditCardHasBeenRecorded" => "boolean"
17
    );
18
19
    private static $field_labels = array(
0 ignored issues
show
Unused Code introduced by
The property $field_labels is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
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