PayPalExperienceContext   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 75
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 21
c 1
b 0
f 0
dl 0
loc 75
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setBrandName() 0 7 1
A setStoredPaymentSource() 0 20 2
A setReturnAndCancelUrl() 0 8 1
1
<?php
2
3
namespace Srmklive\PayPal\Traits;
4
5
trait PayPalExperienceContext
6
{
7
    /**
8
     * @var array
9
     */
10
    protected $experience_context = [];
11
12
    /**
13
     * Set Brand Name when setting experience context for payment.
14
     *
15
     * @param string $brand
16
     *
17
     * @return \Srmklive\PayPal\Services\PayPal
18
     */
19
    public function setBrandName(string $brand): \Srmklive\PayPal\Services\PayPal
20
    {
21
        $this->experience_context = array_merge($this->experience_context, [
22
            'brand_name' => $brand,
23
        ]);
24
25
        return $this;
26
    }
27
28
    /**
29
     * Set return & cancel urls.
30
     *
31
     * @param string $return_url
32
     * @param string $cancel_url
33
     *
34
     * @return \Srmklive\PayPal\Services\PayPal
35
     */
36
    public function setReturnAndCancelUrl(string $return_url, string $cancel_url): \Srmklive\PayPal\Services\PayPal
37
    {
38
        $this->experience_context = array_merge($this->experience_context, [
39
            'return_url' => $return_url,
40
            'cancel_url' => $cancel_url,
41
        ]);
42
43
        return $this;
44
    }
45
46
    /**
47
     * Set stored payment source.
48
     *
49
     * @param string      $initiator
50
     * @param string      $type
51
     * @param string      $usage
52
     * @param bool        $previous_reference
53
     * @param string|null $previous_transaction_id
54
     * @param string|null $previous_transaction_date
55
     * @param string|null $previous_transaction_reference_number
56
     * @param string|null $previous_transaction_network
57
     *
58
     * @return \Srmklive\PayPal\Services\PayPal
59
     */
60
    public function setStoredPaymentSource(string $initiator, string $type, string $usage, bool $previous_reference = false, string $previous_transaction_id = null, string $previous_transaction_date = null, string $previous_transaction_reference_number = null, string $previous_transaction_network = null): \Srmklive\PayPal\Services\PayPal
61
    {
62
        $this->experience_context = array_merge($this->experience_context, [
63
            'stored_payment_source' => [
64
                'payment_initiator' => $initiator,
65
                'payment_type'      => $type,
66
                'usage'             => $usage,
67
            ],
68
        ]);
69
70
        if ($previous_reference === true) {
71
            $this->experience_context['stored_payment_source']['previous_network_transaction_reference'] = [
72
                'id'                        => $previous_transaction_id,
73
                'date'                      => $previous_transaction_date,
74
                'acquirer_reference_number' => $previous_transaction_reference_number,
75
                'network'                   => $previous_transaction_network,
76
            ];
77
        }
78
79
        return $this;
80
    }
81
}
82