Payment::create()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
1
<?php
2
3
namespace tbclla\Revolut\Resources;
4
5
use tbclla\Revolut\Builders\PaymentBuilder;
6
use tbclla\Revolut\Interfaces\Buildable;
7
8
class Payment extends Resource implements Buildable
9
{
10
    /**
11
     * The enpoint for payment requests
12
     * 
13
     * @var string
14
     */
15
    const ENDPOINT = '/pay';
16
17
    /**
18
     * @see https://revolut-engineering.github.io/api-docs/business-api/#payments-create-payment Official API documentation
19
     */
20
    public function create(array $json)
21
    {
22
        return $this->client->post(self::ENDPOINT, ['json' => $json]);
23
    }
24
25
    /**
26
     * Schedule a payment for up to 30 days
27
     * 
28
     * @see https://revolut-engineering.github.io/api-docs/business-api/#payments-schedule-payment Official API documentation
29
     * @param array $json The request parameters
30
     * @param string $date a future ISO date (Up to 30 days)
31
     * @return array The response body
32
     * @throws \tbclla\Revolut\Exceptions\ApiException if the client responded with a 4xx-5xx response
33
     * @throws \tbclla\Revolut\Exceptions\AppUnauthorizedException if the app needs to be re-authorized
34
     */
35
    public function schedule(array $json, string $date)
36
    {
37
        return $this->create(array_merge($json, ['schedule_for' => $date]));
38
    }
39
40
    /**
41
     * Cancel a scheduled payment
42
     * 
43
     * @see https://revolut-engineering.github.io/api-docs/business-api/#payments-cancel-payment Official API documentation
44
     * @param string $id The ID of the payment in UUID format
45
     * @return void
46
     * @throws \tbclla\Revolut\Exceptions\ApiException if the client responded with a 4xx-5xx response
47
     * @throws \tbclla\Revolut\Exceptions\AppUnauthorizedException if the app needs to be re-authorized
48
     */
49
    public function cancel(string $id) : void
50
    {
51
        $this->client->delete('/transaction/' . $id);
52
    }
53
    
54
    /**
55
     * @return \tbclla\Revolut\Builders\PaymentBuilder
56
     */
57
    public function build()
58
    {
59
        return new PaymentBuilder($this, $this->client->generateRequestId());
60
    }
61
}
62