Skip to content

Commit 4286c4e

Browse files
committed
[add] Payment methods API
1 parent 98400cd commit 4286c4e

File tree

2 files changed

+44
-12
lines changed

2 files changed

+44
-12
lines changed

src/BuilderAbstract.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public static abstract function getPreviousOrders($customerID);
2525

2626
public static function integerPrice($price)
2727
{
28-
return intval(round(self::$centsPerWhole * $price));
28+
return intval(round(self::$centsPerWhole * (float) $price));
2929
}
3030

3131
protected static function dateOrBlank($date)
@@ -313,15 +313,15 @@ public function items()
313313
$this->extraItems()
314314
);
315315
}
316-
316+
317317
public function productItems(){
318318
return array();
319319
}
320320

321321
public function handlingItems(){
322322
return array();
323323
}
324-
324+
325325
public function discountItems(){
326326
return array();
327327
}

src/Client.php

Lines changed: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ public function startSolicitation($order)
5050
$this->success = true;
5151
$this->log("Start " . $this->status . ": Ok!");
5252
} elseif ($this->status >= 200 && $this->status <= 299 || $this->status == 409) {
53+
$this->success = false;
5354
$this->json = json_decode($this->curl_result, true); // return array, not object
5455
$this->log("Start " . $this->status . ": " . $this->curl_result);
5556
}
@@ -124,16 +125,16 @@ public function getIdentificationForm($uri, $options = array())
124125
$options["product"] = array_key_exists('product', $options) ? $options["product"] : "i1";
125126
$options["ajax"] = (isset($options["ajax"]) && $options["ajax"]) ? "true" : "false";
126127
$this->initCurl($uri . '/form_v2' . '?' . http_build_query($options));
127-
curl_setopt($this->ch, CURLOPT_CUSTOMREQUEST, "GET");
128+
curl_setopt($this->ch, CURLOPT_CUSTOMREQUEST, 'GET');
128129
curl_setopt($this->ch, CURLOPT_HTTPHEADER, array('Accept: text/html'));
129130
$this->sendRequest();
130131

131132
if ($this->status >= 200 && $this->status <= 299) {
132133
curl_close($this->ch);
133134
$this->success = true;
134-
135135
return $this->curl_result;
136136
} else {
137+
$this->success = false;
137138
$this->log("Error " . $this->status . ": " . print_r($this->curl_result, true));
138139
}
139140
curl_close($this->ch);
@@ -150,9 +151,9 @@ public function sendIdentificationForm($uri, $options = array())
150151
if ($this->status >= 200 && $this->status <= 299) {
151152
curl_close($this->ch);
152153
$this->success = true;
153-
154154
return $this->curl_result;
155155
} else {
156+
$this->success = false;
156157
$this->log("Error " . $this->status . ": " . print_r($this->curl_result, true));
157158
}
158159
curl_close($this->ch);
@@ -170,6 +171,7 @@ public function startCards($order)
170171
$this->success = true;
171172
$this->log("Start " . $this->status . ": Ok!");
172173
} elseif ($this->status >= 200 && $this->status <= 299 || $this->status == 409) {
174+
$this->success = false;
173175
$this->json = json_decode($this->curl_result, true); // return array, not object
174176
$this->log("Start " . $this->status . ": " . $this->curl_result);
175177
}
@@ -179,10 +181,10 @@ public function startCards($order)
179181
public function getCardsForm($uri, $options = array())
180182
{
181183
$this->initCurl($uri . '?' . http_build_query($options));
182-
curl_setopt($this->ch, CURLOPT_CUSTOMREQUEST, "GET");
184+
curl_setopt($this->ch, CURLOPT_CUSTOMREQUEST, 'GET');
183185
curl_setopt($this->ch, CURLOPT_HTTPHEADER, array('Accept: text/html'));
184186
$this->sendRequest();
185-
187+
$this->success = false;
186188
if ($this->status >= 200 && $this->status <= 299) {
187189
$this->success = true;
188190
$this->json = json_decode($this->curl_result, true); // return array, not object
@@ -205,19 +207,41 @@ public function qualifyForstartCards($order)
205207
);
206208
}
207209

210+
public function getMerchantPaymentMethods($merchant)
211+
{
212+
$this->getPaymentMethods($this->_endpoint . '/merchants/' . $merchant);
213+
}
214+
215+
public function getPaymentMethods($uri, $options = array())
216+
{
217+
$this->initCurl($uri . '/payment_methods' . (count($options)>0? '?' . http_build_query($options):''));
218+
curl_setopt($this->ch, CURLOPT_CUSTOMREQUEST, 'GET');
219+
curl_setopt($this->ch, CURLOPT_HTTPHEADER, array('Accept: text/html'));
220+
$this->sendRequest();
221+
$this->success = false;
222+
if ($this->status >= 200 && $this->status <= 299) {
223+
$this->success = true;
224+
$this->json = json_decode($this->curl_result, true); // return array, not object
225+
} elseif ($this->status >= 400 && $this->status <= 499) {
226+
$this->log("Error " . $this->status . ": " . print_r($this->curl_result, true));
227+
} else {
228+
$this->log("Error " . $this->status . ": " . print_r($this->curl_result, true));
229+
}
230+
curl_close($this->ch);
231+
}
232+
208233
public function getCreditAgreements($amount, $merchant)
209234
{
210235
$uri = $this->_endpoint . '/merchants/' . $merchant . '/credit_agreements?total_with_tax=' . $amount . '&currency=EUR&locale=es-ES&country=ES';
211236
$this->initCurl($uri);
212-
curl_setopt($this->ch, CURLOPT_CUSTOMREQUEST, "GET");
237+
curl_setopt($this->ch, CURLOPT_CUSTOMREQUEST, 'GET');
213238
$this->sendRequest();
214-
215239
if ($this->status >= 200 && $this->status <= 299) {
216240
$this->success = true;
217241
curl_close($this->ch);
218-
219242
return json_decode($this->curl_result, true);
220243
} else {
244+
$this->success = false;
221245
$this->log("Error " . $this->status . ": " . print_r($this->curl_result, true));
222246
}
223247
curl_close($this->ch);
@@ -234,6 +258,7 @@ public function updateOrder($uri, $order)
234258
if ($this->status >= 200 && $this->status <= 299) {
235259
$this->success = true;
236260
} elseif ($this->status == 409) {
261+
$this->success = false;
237262
$this->cart_has_changed = true;
238263
$this->json = json_decode($this->curl_result, true);
239264
}
@@ -249,6 +274,7 @@ public function sendDeliveryReport($delivery_report)
249274
$this->success = true;
250275
$this->log("Delivery " . $this->status . ": Ok!");
251276
} elseif ($this->status >= 200 && $this->status <= 299 || $this->status == 409) {
277+
$this->success = false;
252278
$this->json = json_decode($this->curl_result, true); // return array, not object
253279
$this->log("Delivery " . $this->status . ": " . print_r($this->json, true));
254280
}
@@ -266,12 +292,13 @@ public function orderUpdate($order)
266292
if ($this->status >= 200 && $this->status <= 299) {
267293
$this->success = true;
268294
} elseif ($this->status == 409) {
295+
$this->success = false;
269296
$this->cart_has_changed = true;
270297
$this->json = json_decode($this->curl_result, true);
271298
}
272299
curl_close($this->ch);
273300
}
274-
301+
275302
public function callCron($cron_url)
276303
{
277304
$this->_user_agent = 'sequra-cron';
@@ -303,6 +330,11 @@ public function cartHasChanged()
303330
return $this->cart_has_changed;
304331
}
305332

333+
public function getRawResult()
334+
{
335+
return $this->curl_result;
336+
}
337+
306338
public function getOrderUri()
307339
{
308340
if (preg_match('/^Location:\s+([^\n\r]+)/mi', $this->headers, $m)) {

0 commit comments

Comments
 (0)