summaryrefslogtreecommitdiffstats
path: root/vendor/paypal/paypal-checkout-sdk/samples/AuthorizeIntentExamples/RunAll.php
blob: 002f4e257d347280f2da2913a191a3cbb068fc68 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<?php

require __DIR__ . '/../../vendor/autoload.php';

use Sample\AuthorizeIntentExamples\CreateOrder;
use Sample\AuthorizeIntentExamples\AuthorizeOrder;
use Sample\AuthorizeIntentExamples\CaptureOrder;
use Sample\RefundOrder;

$order = CreateOrder::createOrder();

print "Creating Order...\n";
$orderId = "";
if ($order->statusCode == 201)
{
    $orderId = $order->result->id;
    print "Links:\n";
    for ($i = 0; $i < count($order->result->links); ++$i)
    {
        $link = $order->result->links[$i];
        print "\t{$link->rel}: {$link->href}\tCall Type: {$link->method}\n";
    }
    print "Created Successfully\n";
    print "Copy approve link and paste it in browser. Login with buyer account and follow the instructions.\nOnce approved hit enter...\n";
}
else {
    exit(1);
}

$handle = fopen ("php://stdin","r");
$line = fgets($handle);
fclose($handle);

print "Authorizing Order...\n";
$response = AuthorizeOrder::authorizeOrder($orderId);
$authId = "";

if ($response->statusCode == 201)
{
    print "Authorized Successfully\n";
    $authId = $response->result->purchase_units[0]->payments->authorizations[0]->id;
}
else {
    exit(1);
}

print "\nCapturing Order...\n";
$response = CaptureOrder::captureOrder($authId);
if ($response->statusCode == 201)
{
    print "Captured Successfully\n";
    print "Status Code: {$response->statusCode}\n";
    print "Status: {$response->result->status}\n";
    $captureId = $response->result->id;
    print "Capture ID: {$captureId}\n";
    print "Links:\n";
    for ($i = 0; $i < count($response->result->links); ++$i){
        $link = $response->result->links[$i];
        print "\t{$link->rel}: {$link->href}\tCall Type: {$link->method}\n";
    }
}
else {
    exit(1);
}

print "\nRefunding Order...\n";
$response = RefundOrder::refundOrder($captureId);
if ($response->statusCode == 201)
{
    print "Refunded Successfully\n";
    print "Status Code: {$response->statusCode}\n";
    print "Status: {$response->result->status}\n";
    print "Refund ID: {$response->result->id}\n";
    print "Links:\n";
    for ($i = 0; $i < count($response->result->links); ++$i){
        $link = $response->result->links[$i];
        print "\t{$link->rel}: {$link->href}\tCall Type: {$link->method}\n";
    }
}
else {
    exit(1);
}