|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Omnipay\GoCardless; |
|
4
|
|
|
|
|
5
|
|
|
use Omnipay\Common\Exception\RuntimeException; |
|
6
|
|
|
use Omnipay\GoCardless\AbstractGateway; |
|
7
|
|
|
use Omnipay\GoCardless\Message\FetchEventRequest; |
|
8
|
|
|
use Omnipay\GoCardless\Message\FetchPurchaseRequest; |
|
9
|
|
|
use Omnipay\GoCardless\Message\RedirectCompleteFlowRequest; |
|
10
|
|
|
use Omnipay\GoCardless\Message\RedirectCompleteFlowResponse; |
|
11
|
|
|
use Omnipay\GoCardless\Message\RedirectFlowRequest; |
|
12
|
|
|
use Omnipay\GoCardless\Message\RedirectFlowResponse; |
|
13
|
|
|
use Omnipay\GoCardless\Message\PurchaseRequest; |
|
14
|
|
|
use Omnipay\GoCardless\Message\WebhookEventNotification; |
|
15
|
|
|
use Omnipay\GoCardless\Message\WebhookNotification; |
|
16
|
|
|
|
|
17
|
|
|
class RedirectFlowGateway extends AbstractGateway |
|
18
|
|
|
{ |
|
19
|
|
|
public function getName() |
|
20
|
|
|
{ |
|
21
|
|
|
return 'GoCardless Redirect Flow'; |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
// @todo note: might need to do this/add redirectFlowId accessors in order to get superclass unit tests working |
|
25
|
|
|
// but can focus on those after getting the core tests done |
|
26
|
|
|
// public function getDefaultParameters() |
|
27
|
|
|
// { |
|
28
|
|
|
// return parent::getDefaultParameters() + ['redirectFlowId' => null]; |
|
29
|
|
|
// } |
|
30
|
|
|
|
|
31
|
|
|
// @todo authorize? |
|
32
|
|
|
// @todo completeAuthorize? |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* Begin Redirect flow |
|
36
|
|
|
* |
|
37
|
|
|
* Treats a mandate as a 'card' |
|
38
|
|
|
* |
|
39
|
|
|
* @return RedirectFlowRequest |
|
40
|
|
|
*/ |
|
41
|
|
|
public function createCard(array $parameters = array()) |
|
42
|
|
|
{ |
|
43
|
|
|
return $this->redirectFlow($parameters); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* Complete Redirect flow |
|
48
|
|
|
* |
|
49
|
|
|
* Treats a mandate as a 'card' |
|
50
|
|
|
* |
|
51
|
|
|
* @return RedirectCompleteFlowRequest |
|
52
|
|
|
*/ |
|
53
|
|
|
public function completeCreateCard(array $parameters = array()) |
|
54
|
|
|
{ |
|
55
|
|
|
return $this->completeRedirectFlow($parameters); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* Begin Redirect Flow |
|
60
|
|
|
* |
|
61
|
|
|
* @return RedirectFlowRequest |
|
62
|
|
|
*/ |
|
63
|
|
|
public function redirectFlow(array $parameters = array()) |
|
64
|
|
|
{ |
|
65
|
|
|
return $this->createRequest(RedirectFlowRequest::class, $parameters); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* Complete Redirect Flow |
|
70
|
|
|
* |
|
71
|
|
|
* @return RedirectCompleteFlowRequest |
|
72
|
|
|
*/ |
|
73
|
|
|
public function completeRedirectFlow(array $parameters = array()) |
|
74
|
|
|
{ |
|
75
|
|
|
return $this->createRequest(RedirectCompleteFlowRequest::class, $parameters); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* Make a payment, or begin redirect flow if no mandate has been given |
|
80
|
|
|
* |
|
81
|
|
|
* @return RedirectFlowRequest|PurchaseRequest |
|
82
|
|
|
*/ |
|
83
|
|
|
public function purchase(array $parameters = array()) |
|
84
|
|
|
{ |
|
85
|
|
|
if (empty($parameters['mandateId'])) { |
|
86
|
|
|
return $this->redirectFlow($parameters); |
|
87
|
|
|
} |
|
88
|
|
|
return $this->createRequest(PurchaseRequest::class, $parameters); |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
/** |
|
92
|
|
|
* Extract the mandate from a completed redirect flow, then make a payment |
|
93
|
|
|
* |
|
94
|
|
|
* @return RedirectCompleteFlowReponse|PurchaseRequest |
|
|
|
|
|
|
95
|
|
|
*/ |
|
96
|
|
|
public function completePurchase(array $parameters = array()) |
|
97
|
|
|
{ |
|
98
|
|
|
if (empty($parameters['mandateId'])) { |
|
99
|
|
|
$flowResponse = $this->completeRedirectFlow($parameters)->send(); |
|
100
|
|
|
if (!$flowResponse->isSuccessful()) { |
|
101
|
|
|
// @todo change to use `->getRequest()` so it can be re-tried by calling application? |
|
102
|
|
|
return $flowResponse; |
|
|
|
|
|
|
103
|
|
|
} |
|
104
|
|
|
$parameters['mandateId'] = $flowResponse->getMandateId(); |
|
105
|
|
|
} |
|
106
|
|
|
return $this->purchase($parameters); |
|
|
|
|
|
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
/** |
|
110
|
|
|
* Parse webhook to validate/process pending transactions |
|
111
|
|
|
*/ |
|
112
|
|
|
public function acceptNotification(array $parameters = array()) |
|
113
|
|
|
{ |
|
114
|
|
|
return $this->createRequest(WebhookEventNotification::class, $parameters); |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
/** |
|
118
|
|
|
* Parse batch of webhooks to validate and provide events for {@see self::acceptNotification()} |
|
119
|
|
|
* |
|
120
|
|
|
* @todo do we both with parameters? |
|
121
|
|
|
*/ |
|
122
|
|
|
public function acceptNotificationBatch(array $parameters = array()) |
|
123
|
|
|
{ |
|
124
|
|
|
return $this->createRequest(WebhookNotification::class, $parameters); |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
|
|
/** |
|
128
|
|
|
* Fetch the details for a specific event (webhook notification) |
|
129
|
|
|
*/ |
|
130
|
|
|
public function fetchEvent(array $parameters = array()) |
|
131
|
|
|
{ |
|
132
|
|
|
return $this->createRequest(FetchEventRequest::class, $parameters); |
|
133
|
|
|
} |
|
134
|
|
|
|
|
135
|
|
|
/** |
|
136
|
|
|
* Fetch the details for a specific payment |
|
137
|
|
|
*/ |
|
138
|
|
|
public function fetchPurchase(array $parameters = array()) |
|
139
|
|
|
{ |
|
140
|
|
|
return $this->createRequest(FetchPurchaseRequest::class, $parameters); |
|
141
|
|
|
} |
|
142
|
|
|
} |
|
143
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths