Skip to content

Commit 57f4d0f

Browse files
author
has.well
committed
Add subscription stop api
1 parent 664c8e2 commit 57f4d0f

3 files changed

Lines changed: 128 additions & 1 deletion

File tree

examples/Subscription/cancel.php

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<?php
2+
require_once '../configuration.php';
3+
require_once SDK_ROOTPATH . '/../vendor/autoload.php';
4+
5+
6+
//Payment calendar (host-to-host)
7+
try {
8+
//Minimal data set, all other required params will generated automatically
9+
$TestOrderData = [
10+
'order_id' => time(),
11+
'card_number' => '4444555511116666',
12+
'cvv2' => '333',
13+
'expiry_date' => '1232',
14+
'currency' => 'UAH',
15+
'amount' => 1000,
16+
'client_ip' => '127.2.2.1',
17+
'recurring_data' => [
18+
'start_time' => date("Y-m-d"),
19+
'amount' => 1000,
20+
'every' => 30,
21+
'period' => 'day',
22+
'state' => 'y',
23+
'readonly' => 'y'
24+
]
25+
];
26+
//Call method to start calendar order subscription
27+
\Cloudipsp\Configuration::setApiVersion('2.0'); //allow only json, api protocol 2.0
28+
$orderData = Cloudipsp\Pcidss::start($TestOrderData);
29+
$cancel = Cloudipsp\Subscription::stop('1396424_26aed9412954da8a12ff36fcdeee10db');
30+
//getting returned data
31+
?>
32+
<!doctype html>
33+
<html lang="en-US">
34+
<head>
35+
<meta charset="UTF-8">
36+
<title>Generate subscription Payment token</title>
37+
<style>
38+
table tr td, table tr th {
39+
padding: 10px;
40+
}
41+
</style>
42+
</head>
43+
<body>
44+
<table style="margin: auto;" border="1">
45+
<thead>
46+
<tr>
47+
<th style="text-align: center" colspan="2">Request Data:</th>
48+
</tr>
49+
<tr>
50+
<th style="text-align: left"
51+
colspan="2"><?php printf("<pre>%s</pre>", json_encode(['request' => $TestOrderData], JSON_PRETTY_PRINT)) ?></th>
52+
</tr>
53+
</thead>
54+
<tbody>
55+
<tr>
56+
<td>Normal cancel response:</td>
57+
<td>
58+
<pre><?php print_r($cancel->getData()) ?></pre>
59+
</td>
60+
</tr>
61+
<tr>
62+
<td>Response subscription stop order_id:</td>
63+
<td><?php print_r($orderData->getData()['order_id']) ?></td>
64+
</tr>
65+
</tbody>
66+
</table>
67+
</body>
68+
</html>
69+
<?php
70+
} catch (\Exception $e) {
71+
echo "Fail: " . $e->getMessage();
72+
}

lib/Api/Order/Subscription.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
namespace Cloudipsp\Api\Order;
4+
5+
use Cloudipsp\Api\Api;
6+
7+
class Subscription extends Api
8+
{
9+
private $url = '/subscription/';
10+
/**
11+
* Minimal required params
12+
* @var array
13+
*/
14+
private $requiredParams = [
15+
'merchant_id' => 'integer',
16+
'action' => 'string',
17+
'order_id' => 'string'
18+
];
19+
20+
/**
21+
* @param $data
22+
* @param array $headers
23+
* @return mixed
24+
* @throws \Cloudipsp\Exception\ApiException
25+
*/
26+
public function get($data, $headers = [])
27+
{
28+
$requestData = $this->prepareParams($data);
29+
$this->validate($requestData, $this->requiredParams);
30+
return $this->Request($method = 'POST', $this->url, $headers, $requestData);
31+
}
32+
}

lib/Subscription.php

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
namespace Cloudipsp;
55

66
use Cloudipsp\Api\Checkout as Api;
7+
use Cloudipsp\Api\Order as ApiRecurring;
78
use Cloudipsp\Response\Response;
89

910
class Subscription
@@ -44,6 +45,28 @@ public static function url($data, $headers = [])
4445
return new Response($result);
4546
}
4647

48+
/**
49+
* stop calendar recurring payments
50+
* @param $order_id
51+
* @param array $headers
52+
* @return Response
53+
* @throws Exception\ApiException
54+
*/
55+
public static function stop($order_id, $headers = [])
56+
{
57+
if (\Cloudipsp\Configuration::getApiVersion() !== self::$requiredApiVersion) {
58+
trigger_error('Reccuring_data allowed only for api version \'2.0\'', E_USER_NOTICE);
59+
\Cloudipsp\Configuration::setApiVersion(self::$requiredApiVersion);
60+
}
61+
$api = new ApiRecurring\Subscription();
62+
$data = [
63+
"order_id" => $order_id,
64+
"action" => "stop"
65+
];
66+
$result = $api->get($data, $headers);
67+
return new Response($result);
68+
}
69+
4770
/**
4871
* return checkout token with calendar
4972
* @param $data
@@ -64,4 +87,4 @@ public static function token($data, $headers = [])
6487
}
6588

6689

67-
}
90+
}

0 commit comments

Comments
 (0)