Passed
Push — v3.0 ( bac5d5...2d99c7 )
by Raza
01:59
created

PayPalExperienceContext::setBrandName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 7
rs 10
cc 1
nc 1
nop 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
     * @param string $brand
15
     *
16
     * @return \Srmklive\PayPal\Services\PayPal
17
     */
18
    public function setBrandName(string $brand): \Srmklive\PayPal\Services\PayPal
19
    {
20
        $this->experience_context = array_merge($this->experience_context, [
21
            'brand_name' => $brand,
22
        ]);
23
24
        return $this;
25
    }
26
27
    /**
28
     * Set return & cancel urls.
29
     *
30
     * @param string $return_url
31
     * @param string $cancel_url
32
     *
33
     * @return \Srmklive\PayPal\Services\PayPal
34
     */
35
    public function setReturnAndCancelUrl(string $return_url, string $cancel_url): \Srmklive\PayPal\Services\PayPal
36
    {
37
        $this->experience_context = array_merge($this->experience_context, [
38
            'return_url' => $return_url,
39
            'cancel_url' => $cancel_url,
40
        ]);
41
42
        return $this;
43
    }
44
45
    /**
46
     * Set stored payment source.
47
     *
48
     * @param string      $initiator
49
     * @param string      $type
50
     * @param string      $usage
51
     * @param bool        $previous_reference
52
     * @param string|null $previous_transaction_id
53
     * @param string|null $previous_transaction_date
54
     * @param string|null $previous_transaction_reference_number
55
     * @param string|null $previous_transaction_network
56
     *
57
     * @return \Srmklive\PayPal\Services\PayPal
58
     */
59
    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
60
    {
61
        $this->experience_context = array_merge($this->experience_context, [
62
            'stored_payment_source' => [
63
                'payment_initiator' => $initiator,
64
                'payment_type'      => $type,
65
                'usage'             => $usage,
66
            ],
67
        ]);
68
69
        if ($previous_reference === true) {
70
            $this->experience_context['stored_payment_source']['previous_network_transaction_reference'] = [
71
                'id'                        => $previous_transaction_id,
72
                'date'                      => $previous_transaction_date,
73
                'acquirer_reference_number' => $previous_transaction_reference_number,
74
                'network'                   => $previous_transaction_network,
75
            ];
76
        }
77
78
        return $this;
79
    }
80
}
81