Passed
Pull Request — v3.0 (#585)
by
unknown
15:23
created

BillingAgreements::createBillingAgreement()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
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 6
rs 10
cc 1
nc 1
nop 1
1
<?php
2
3
namespace Srmklive\PayPal\Traits\PayPalAPI;
4
5
trait BillingAgreements {
6
7
    /**
8
     * Creates a billing agreement token.
9
     *
10
     * @param array $data
11
     *
12
     * @throws \Throwable
13
     *
14
     * @return array|\Psr\Http\Message\StreamInterface|string
15
     *
16
     * @see https://developer.paypal.com/limited-release/reference-transactions/#link-createbillingagreementtoken
17
     */
18
    public function createBillingAgreementToken (array $data) {
19
        $this->apiEndPoint = 'v1/billing-agreements/agreement-tokens';
20
21
        $this->options['json'] = (object) $data;
22
23
        $this->verb = 'post';
24
25
        return $this->doPayPalRequest();
26
    }
27
28
    /**
29
     * After payer approval, use a billing agreement token to create the agreement.
30
     *
31
     * @param string $billingAgreementToken
32
     *
33
     * @throws \Throwable
34
     *
35
     * @return array|\Psr\Http\Message\StreamInterface|string
36
     *
37
     * @see https://developer.paypal.com/limited-release/reference-transactions/#link-createbillingagreement
38
     */
39
    public function createBillingAgreement (string $billingAgreementToken) {
40
        $this->apiEndPoint = "v1/billing-agreements/{$billingAgreementToken}/agreements";
41
42
        $this->verb = 'post';
43
44
        return $this->doPayPalRequest();
45
    }
46
}
47