Passed
Push — v3.0 ( cb53e2...ac3631 )
by Raza
02:38
created

Helpers::setTokenSource()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 4
c 1
b 0
f 0
dl 0
loc 8
rs 10
cc 1
nc 1
nop 2
1
<?php
2
3
namespace Srmklive\PayPal\Traits\PayPalAPI\PaymentMethodsTokens;
4
5
use Carbon\Carbon;
6
use Illuminate\Support\Str;
7
use Throwable;
8
9
trait Helpers
10
{
11
    /**
12
     * @var array
13
     */
14
    protected $token_source = [];
15
16
    /**
17
     * @var array
18
     */
19
    protected $customer_source = [];
20
21
    /**
22
     * Set payment method token by token id.
23
     *
24
     * @param string $id
25
     * @param string $type
26
     *
27
     * @return \Srmklive\PayPal\Services\PayPal  
28
     */
29
    public function setTokenSource(string $id, string $type)
30
    {
31
        $this->token_source = [
32
            'id'    => $id,
33
            'type'  => $type,
34
        ];
35
36
        return $this;
37
    }
38
39
    /**
40
     * Set payment method token customer id.
41
     *
42
     * @param string $id
43
     *
44
     * @return \Srmklive\PayPal\Services\PayPal  
45
     */
46
    public function setCustomerSource(string $id)
47
    {
48
        $this->customer_source = [
49
            'id' => $id,
50
        ];
51
52
        return $this;
53
    }    
54
55
    /**
56
     * Send request for creating payment method token.
57
     *
58
     * @throws \Throwable
59
     *
60
     * @return array|\Psr\Http\Message\StreamInterface|string
61
     */
62
    public function sendTokenRequest()
63
    {
64
        $token_payload = ['payment_source' => null];
65
66
        if (!empty($this->token_source)) {
67
            $token_payload['payment_source']['token'] = $this->token_source;
68
        }     
69
70
        if (!empty($this->customer_source)) {
71
            $token_payload['customer'] = $this->customer_source;
72
        }
73
74
        return $this->createPaymentSourceToken(array_filter($token_payload));
0 ignored issues
show
Bug introduced by
It seems like createPaymentSourceToken() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

74
        return $this->/** @scrutinizer ignore-call */ createPaymentSourceToken(array_filter($token_payload));
Loading history...
75
    }
76
}
77