Skip to content

Commit 6b88ba2

Browse files
authored
Merge pull request #2 from treeStoneIT/merge-converge-request
Merge converge request
2 parents 89feda4 + 7ff71fd commit 6b88ba2

File tree

5 files changed

+112
-35
lines changed

5 files changed

+112
-35
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ Please review [our security policy](../../security/policy) on how to report secu
8484

8585
## Credits
8686

87-
This package is built as a Laravel wrapper for the [PHP Converge API](https://github.com/wwwroth/php-converge-api) built by [Phillip Roth](https://github.com/wwwroth)
87+
This package is built as a Laravel wrapper using the code in [PHP Converge API](https://github.com/wwwroth/php-converge-api) built by [Phillip Roth](https://github.com/wwwroth)
8888

8989
- [Bomshteyn Consulting](https://github.com/treestoneit)
9090
- [All Contributors](../../contributors)

composer.json

+2-8
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,16 @@
1717
],
1818
"require": {
1919
"php": "^7.4|^8.0",
20+
"ext-curl": "*",
2021
"spatie/laravel-package-tools": "^1.1",
21-
"illuminate/contracts": "^8.0",
22-
"wwwroth/php-converge-api": "dev-master"
22+
"illuminate/contracts": "^8.0"
2323
},
2424
"require-dev": {
2525
"orchestra/testbench": "^6.0",
2626
"phpunit/phpunit": "^9.3",
2727
"spatie/laravel-ray": "^1.9",
2828
"vimeo/psalm": "^4.4"
2929
},
30-
"repositories": [
31-
{
32-
"type": "vcs",
33-
"url": "https://github.com/bomshteyn/php-converge-api"
34-
}
35-
],
3630
"autoload": {
3731
"psr-4": {
3832
"Treestoneit\\LaravelConvergeApi\\": "src"

src/Converge.php

+2-26
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace Treestoneit\LaravelConvergeApi;
44

55
use Illuminate\Support\Facades\Config;
6-
use wwwroth\Converge\Converge as ConvergePHP;
76

87
class Converge
98
{
@@ -12,11 +11,11 @@ class Converge
1211
* Full documentation can be found here:
1312
* @link https://developer.elavon.com/na/docs/converge/1.0.0/integration-guide/transaction_types/credit_card
1413
*/
15-
public ConvergePHP $converge;
14+
public ConvergeRequest $converge;
1615

1716
public function __construct()
1817
{
19-
$this->converge = new ConvergePHP([
18+
$this->converge = new ConvergeRequest([
2019
'merchant_id' => Config::get('converge-api.merchant_id'),
2120
'user_id' => Config::get('converge-api.user_id'),
2221
'pin' => Config::get('converge-api.pin'),
@@ -32,7 +31,6 @@ public function __construct()
3231
* @param array $params
3332
*
3433
* @return array
35-
* @throws \wwwroth\Converge\Exceptions\ConvergeException
3634
*/
3735
public function authOnly(array $params): array
3836
{
@@ -47,7 +45,6 @@ public function authOnly(array $params): array
4745
* @param array $params
4846
*
4947
* @return array
50-
* @throws \wwwroth\Converge\Exceptions\ConvergeException
5148
*/
5249
public function sale(array $params): array
5350
{
@@ -62,7 +59,6 @@ public function sale(array $params): array
6259
* @param array $params
6360
*
6461
* @return array
65-
* @throws \wwwroth\Converge\Exceptions\ConvergeException
6662
*/
6763
public function verify(array $params): array
6864
{
@@ -77,7 +73,6 @@ public function verify(array $params): array
7773
* @param array $params
7874
*
7975
* @return array
80-
* @throws \wwwroth\Converge\Exceptions\ConvergeException
8176
*/
8277
public function balanceInquiry(array $params): array
8378
{
@@ -94,7 +89,6 @@ public function balanceInquiry(array $params): array
9489
* @param array $params
9590
*
9691
* @return array
97-
* @throws \wwwroth\Converge\Exceptions\ConvergeException
9892
*/
9993
public function return(array $params): array
10094
{
@@ -109,7 +103,6 @@ public function return(array $params): array
109103
* @param array $params
110104
*
111105
* @return array
112-
* @throws \wwwroth\Converge\Exceptions\ConvergeException
113106
*/
114107
public function void(array $params): array
115108
{
@@ -124,7 +117,6 @@ public function void(array $params): array
124117
* @param array $params
125118
*
126119
* @return array
127-
* @throws \wwwroth\Converge\Exceptions\ConvergeException
128120
*/
129121
public function complete(array $params): array
130122
{
@@ -141,7 +133,6 @@ public function complete(array $params): array
141133
* @param array $params
142134
*
143135
* @return array
144-
* @throws \wwwroth\Converge\Exceptions\ConvergeException
145136
*/
146137
public function delete(array $params): array
147138
{
@@ -156,7 +147,6 @@ public function delete(array $params): array
156147
* @param array $params
157148
*
158149
* @return array
159-
* @throws \wwwroth\Converge\Exceptions\ConvergeException
160150
*/
161151
public function updateTip(array $params): array
162152
{
@@ -171,7 +161,6 @@ public function updateTip(array $params): array
171161
* @param array $params
172162
*
173163
* @return array
174-
* @throws \wwwroth\Converge\Exceptions\ConvergeException
175164
*/
176165
public function signature(array $params): array
177166
{
@@ -186,7 +175,6 @@ public function signature(array $params): array
186175
* @param array $params
187176
*
188177
* @return array
189-
* @throws \wwwroth\Converge\Exceptions\ConvergeException
190178
*/
191179
public function addRecurring(array $params): array
192180
{
@@ -201,7 +189,6 @@ public function addRecurring(array $params): array
201189
* @param array $params
202190
*
203191
* @return array
204-
* @throws \wwwroth\Converge\Exceptions\ConvergeException
205192
*/
206193
public function updateRecurring(array $params): array
207194
{
@@ -216,7 +203,6 @@ public function updateRecurring(array $params): array
216203
* @param array $params
217204
*
218205
* @return array
219-
* @throws \wwwroth\Converge\Exceptions\ConvergeException
220206
*/
221207
public function deleteRecurring(array $params): array
222208
{
@@ -231,7 +217,6 @@ public function deleteRecurring(array $params): array
231217
* @param array $params
232218
*
233219
* @return array
234-
* @throws \wwwroth\Converge\Exceptions\ConvergeException
235220
*/
236221
public function recurringSale(array $params): array
237222
{
@@ -246,7 +231,6 @@ public function recurringSale(array $params): array
246231
* @param array $params
247232
*
248233
* @return array
249-
* @throws \wwwroth\Converge\Exceptions\ConvergeException
250234
*/
251235
public function addInstallment(array $params): array
252236
{
@@ -261,7 +245,6 @@ public function addInstallment(array $params): array
261245
* @param array $params
262246
*
263247
* @return array
264-
* @throws \wwwroth\Converge\Exceptions\ConvergeException
265248
*/
266249
public function updateInstallment(array $params): array
267250
{
@@ -276,7 +259,6 @@ public function updateInstallment(array $params): array
276259
* @param array $params
277260
*
278261
* @return array
279-
* @throws \wwwroth\Converge\Exceptions\ConvergeException
280262
*/
281263
public function deleteInstallment(array $params): array
282264
{
@@ -291,7 +273,6 @@ public function deleteInstallment(array $params): array
291273
* @param array $params
292274
*
293275
* @return array
294-
* @throws \wwwroth\Converge\Exceptions\ConvergeException
295276
*/
296277
public function installmentSale(array $params): array
297278
{
@@ -306,7 +287,6 @@ public function installmentSale(array $params): array
306287
* @param array $params
307288
*
308289
* @return array
309-
* @throws \wwwroth\Converge\Exceptions\ConvergeException
310290
*/
311291
public function queryToken(array $params): array
312292
{
@@ -321,7 +301,6 @@ public function queryToken(array $params): array
321301
* @param array $params
322302
*
323303
* @return array
324-
* @throws \wwwroth\Converge\Exceptions\ConvergeException
325304
*/
326305
public function updateToken(array $params): array
327306
{
@@ -336,7 +315,6 @@ public function updateToken(array $params): array
336315
* @param array $params
337316
*
338317
* @return array
339-
* @throws \wwwroth\Converge\Exceptions\ConvergeException
340318
*/
341319
public function getToken(array $params): array
342320
{
@@ -351,7 +329,6 @@ public function getToken(array $params): array
351329
* @param array $params
352330
*
353331
* @return array
354-
* @throws \wwwroth\Converge\Exceptions\ConvergeException
355332
*/
356333
public function deleteToken(array $params): array
357334
{
@@ -366,7 +343,6 @@ public function deleteToken(array $params): array
366343
* @param array $params
367344
*
368345
* @return array
369-
* @throws \wwwroth\Converge\Exceptions\ConvergeException
370346
*/
371347
public function custom(string $transactionType, array $params): array
372348
{

src/ConvergeException.php

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
namespace Treestoneit\LaravelConvergeApi;
4+
5+
class ConvergeException extends \Exception
6+
{
7+
}

src/ConvergeRequest.php

+100
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
<?php
2+
3+
namespace Treestoneit\LaravelConvergeApi;
4+
5+
class ConvergeRequest
6+
{
7+
private string $merchant_id;
8+
private string $user_id;
9+
private string $pin;
10+
private bool $demo;
11+
12+
private string $xmlEndpoint;
13+
14+
/**
15+
* Construct Converge Request object with provided settings.
16+
*
17+
* @param array $settings
18+
*
19+
* @throws \Treestoneit\LaravelConvergeApi\ConvergeException
20+
*/
21+
public function __construct(array $settings)
22+
{
23+
$this->validateSettings($settings);
24+
25+
$this->merchant_id = $settings['merchant_id'];
26+
$this->user_id = $settings['user_id'];
27+
$this->pin = $settings['pin'];
28+
29+
if (isset($settings['demo']) && $settings['demo'] == true) {
30+
$this->demo = true;
31+
$this->xmlEndpoint = "https://api.demo.convergepay.com/VirtualMerchantDemo/process.do";
32+
} else {
33+
$this->demo = false;
34+
$this->xmlEndpoint = "https://api.convergepay.com/VirtualMerchant/process.do";
35+
}
36+
}
37+
38+
/**
39+
* Make request to Converge with transaction type and parameters.
40+
* @param $transactionType
41+
* @param array $parameters
42+
* @return array
43+
*/
44+
public function request($transactionType, array $parameters): array
45+
{
46+
return $this->httpRequest(array_merge(['ssl_transaction_type' => $transactionType], $parameters));
47+
}
48+
49+
/**
50+
* Validate provided settings when constructing class.
51+
* @param array $settings
52+
* @return bool
53+
* @throws ConvergeException
54+
*/
55+
private function validateSettings(array $settings): bool
56+
{
57+
if (! isset($settings['merchant_id'])) {
58+
throw new ConvergeException('Please provide a valid merchant id in settings.');
59+
}
60+
if (! isset($settings['user_id'])) {
61+
throw new ConvergeException('Please provide a valid user id in settings.');
62+
}
63+
if (! isset($settings['pin'])) {
64+
throw new ConvergeException('Please provide a valid pin in settings.');
65+
}
66+
67+
return true;
68+
}
69+
70+
/**
71+
* @param $parameters
72+
* @return array
73+
*/
74+
private function httpRequest($parameters): array
75+
{
76+
$parameters['ssl_merchant_id'] = $this->merchant_id;
77+
$parameters['ssl_user_id'] = $this->user_id;
78+
$parameters['ssl_pin'] = $this->pin;
79+
$parameters['ssl_show_form'] = 'false';
80+
$parameters['ssl_result_format'] = 'ascii';
81+
82+
$ch = curl_init($this->xmlEndpoint);
83+
curl_setopt($ch, CURLOPT_POST, true);
84+
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($parameters));
85+
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
86+
87+
// Break out response into array of key value pairs
88+
$response = [];
89+
foreach (explode("\n", curl_exec($ch)) as $part) {
90+
$pParts = explode('=', $part);
91+
if (isset($pParts[1])) {
92+
$response[$pParts[0]] = $pParts[1];
93+
}
94+
}
95+
96+
isset($response['errorCode']) ? $response['success'] = false : $response['success'] = true;
97+
98+
return $response;
99+
}
100+
}

0 commit comments

Comments
 (0)