Completed
Push — master ( 0544e4...785986 )
by
unknown
04:27
created

EcommerceSecurityOrderDecoration   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 6
dl 0
loc 48
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A updateCMSFields() 0 23 3
A onBeforeWrite() 0 14 2
1
<?php
2
3
class EcommerceSecurityOrderDecoration 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...
4
{
5
    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...
6
        'SkipPayment' => 'Boolean'
7
    );
8
9
    public function updateCMSFields(FieldList $fields)
10
    {
11
        if ($this->owner->IsSubmitted()) {
12
            if (! $this->owner->IsPaid()) {
13
                $fields->addFieldsToTab(
14
                    'Root.Payments',
15
                    [
16
                        HeaderField::create(
17
                            'SkipToSecurityChecks',
18
                            'Skip To Security Checks'
19
                        ),
20
                        CheckboxField::create(
21
                            'SkipPayment',
22
                            'Skip Payment'
23
                        )->setDescription(
24
                            'Ticking this checkbox will add a fake "successful" payment to the order,  this allows the order to proceed to the security checks step.
25
                            <br>Make sure to save the order after ticking this checkbox.'
26
                        )
27
                    ]
28
                );
29
            }
30
        }
31
    }
32
33
    /**
34
     * Event handler called before writing to the database.
35
     */
36
    public function onBeforeWrite()
37
    {
38
        parent::onBeforeWrite();
39
        if ($this->owner->SkipPayment) {
0 ignored issues
show
Bug introduced by
The property SkipPayment does not seem to exist in SS_Object.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
40
            $money = Money::create();
41
            $money->setAmount($this->owner->TotalOutstanding());
42
            $payment = EcommercePayment::create();
43
            $payment->Status = 'Success';
44
            $payment->Amount = $money;
45
            $payment->Message = 'This is a fake payment that has been created to allow the order to proceed to the next step, this order has not really been paid for.';
46
            $payment->write();
47
            $this->owner->Payments()->add($payment);
48
        }
49
    }
50
}
51