Skip to content

Commit 8ba91d5

Browse files
authored
Merge pull request #10 from tobz-nz/master
Omnipay v3 support.
2 parents 9f730dd + ccb8b13 commit 8ba91d5

File tree

8 files changed

+60
-41
lines changed

8 files changed

+60
-41
lines changed

.editorconfig

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
end_of_line = lf
6+
insert_final_newline = true
7+
indent_style = space
8+
indent_size = 4
9+
trim_trailing_whitespace = true
10+
11+
[*.md]
12+
trim_trailing_whitespace = false

.travis.yml

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
11
language: php
22

33
php:
4-
- 5.3
5-
- 5.4
6-
- 5.5
7-
- hhvm
4+
- 5.6
5+
- 7.0
6+
- 7.1
7+
- 7.2
8+
- 7.3
9+
- 7.4
810

9-
before_script:
11+
## Cache composer
12+
cache:
13+
directories:
14+
- $HOME/.composer/cache
15+
16+
install:
1017
- composer install -n --dev --prefer-source
1118

12-
script: vendor/bin/phpcs --standard=PSR2 src && vendor/bin/phpunit --coverage-text
19+
script: vendor/bin/phpcs --standard=PSR2 src && vendor/bin/phpunit --coverage-text

composer.json

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,14 @@
3030
}
3131
},
3232
"require": {
33-
"omnipay/common": "~2.0"
33+
"omnipay/common": "^3.0"
3434
},
3535
"require-dev": {
36-
"guzzle/plugin-mock": "~3.1",
37-
"mockery/mockery": "~0.7",
38-
"phpunit/phpunit": "~3.7.0",
39-
"squizlabs/php_codesniffer": "~1.4",
40-
"omnipay/tests": "~2.0"
36+
"mockery/mockery": "^1.3",
37+
"squizlabs/php_codesniffer": "^3.5",
38+
"phpunit/phpunit": "~6",
39+
"omnipay/tests": "^3.1"
4140
},
4241
"extra": {
43-
"branch-alias": {
44-
"dev-master": "2.0.x-dev"
45-
}
4642
}
47-
}
43+
}

src/Message/CompletePurchaseRequest.php

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
namespace Omnipay\Poli\Message;
44

55
use Omnipay\Common\Exception\InvalidRequestException;
6-
use SimpleXMLElement;
76
use Omnipay\Common\Exception\InvalidResponseException;
7+
use SimpleXMLElement;
88

99
/**
1010
* Poli Complete Purchase Request
11-
*
11+
*
1212
* @link http://www.polipaymentdeveloper.com/doku.php?id=gettransaction
1313
*/
1414
class CompletePurchaseRequest extends PurchaseRequest
@@ -39,7 +39,7 @@ public function getData()
3939
}
4040
$data = array();
4141
$data['token'] = $token;
42-
42+
4343
return $data;
4444
}
4545

@@ -50,10 +50,14 @@ public function send()
5050

5151
public function sendData($data)
5252
{
53-
$request = $this->httpClient->get($this->endpoint)
54-
->setAuth($this->getMerchantCode(), $this->getAuthenticationCode());
55-
$request->getQuery()->replace($data);
56-
$httpResponse = $request->send();
53+
$auth = base64_encode($this->getMerchantCode() . ':' . $this->getAuthenticationCode());
54+
$headers = [
55+
'Content-Type' => 'application/json',
56+
'Authorization' => 'basic ' . $auth,
57+
];
58+
59+
$httpResponse = $this->httpClient
60+
->request('get', $this->endpoint, $headers, http_build_query($data));
5761

5862
return $this->response = new CompletePurchaseResponse($this, $httpResponse->getBody());
5963
}

src/Message/FetchCheckoutRequest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,15 @@ public function sendData($data)
5353
$authenticationCode = $this->getAuthenticationCode();
5454
$auth = base64_encode($merchantCode.":".$authenticationCode); //'S61xxxxx:AuthCode123');
5555

56-
$httpRequest = $this->httpClient->get(
56+
$httpResponse = $this->httpClient->request(
57+
'get',
5758
$url,
5859
array(
5960
'Content-Type'=>'application/json',
6061
'Authorization' => 'Basic '.$auth,
6162
)
6263
);
63-
$httpResponse = $httpRequest->send();
64+
6465
return $this->response = new FetchCheckoutResponse($this, $httpResponse->getBody(true));
6566

6667
}

src/Message/PurchaseRequest.php

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -96,20 +96,21 @@ public function sendData($data)
9696
{
9797
$merchantCode = $this->getMerchantCode();
9898
$authenticationCode = $this->getAuthenticationCode();
99-
$auth = base64_encode($merchantCode.":".$authenticationCode); //'S61xxxxx:AuthCode123');
99+
$auth = base64_encode($merchantCode . ":" . $authenticationCode); //'S61xxxxx:AuthCode123');
100100
unset($data['MerchantCode'], $data['AuthenticationCode']);
101101

102102
//$postdata = $this->packageData($data);
103103
$postdata = json_encode($data);
104-
$httpRequest = $this->httpClient->post(
104+
$httpResponse = $this->httpClient->request(
105+
'post',
105106
$this->endpoint,
106107
array(
107-
'Content-Type'=>'application/json',
108-
'Authorization' => 'Basic '.$auth,
108+
'Content-Type' => 'application/json',
109+
'Authorization' => 'Basic ' . $auth,
109110
),
110111
$postdata
111112
);
112-
$httpResponse = $httpRequest->send();
113+
113114
return $this->response = new PurchaseResponse($this, $httpResponse->getBody());
114115
}
115116

@@ -119,18 +120,18 @@ protected function packageData($data)
119120
unset($data['AuthenticationCode']);
120121
$fields = "";
121122
foreach ($data as $field => $value) {
122-
$fields .= str_repeat(" ", 24)."<dco:$field>$value</dco:$field>\n";
123+
$fields .= str_repeat(" ", 24) . "<dco:$field>$value</dco:$field>\n";
123124
}
124125
$namespace = "http://schemas.datacontract.org/2004/07/Centricom.POLi.Services.MerchantAPI.Contracts";
125126
$i_namespace = "http://www.w3.org/2001/XMLSchema-instance";
126127
$dco_namespace = "http://schemas.datacontract.org/2004/07/Centricom.POLi.Services.MerchantAPI.DCO";
127128

128129
return '<?xml version="1.0" encoding="utf-8" ?>
129-
<InitiateTransactionRequest xmlns="'.$namespace.'" xmlns:i="'.$i_namespace.'">
130-
<AuthenticationCode>'. $authenticationcode.'</AuthenticationCode>
131-
<Transaction xmlns:dco="'.$dco_namespace.'">'
132-
.$fields.
133-
'</Transaction>
130+
<InitiateTransactionRequest xmlns="' . $namespace . '" xmlns:i="' . $i_namespace . '">
131+
<AuthenticationCode>' . $authenticationcode . '</AuthenticationCode>
132+
<Transaction xmlns:dco="' . $dco_namespace . '">'
133+
. $fields .
134+
'</Transaction>
134135
</InitiateTransactionRequest>';
135136
}
136137
}

tests/GatewayTest.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public function setUp()
1818
}
1919

2020
public function testPurchaseSuccess()
21-
{
21+
{
2222
$this->setMockHttpResponse('PurchaseRequestSuccess.txt');
2323

2424
$response = $this->gateway->purchase(array(
@@ -94,5 +94,4 @@ public function testNotifyCompletePurchaseSuccess()
9494
$this->assertNull($response->getMessage());
9595
$this->assertEquals("396414606841", $response->getTransactionReference());
9696
}
97-
98-
}
97+
}

tests/Message/PurchaseRequestTest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,7 @@ public function testMerchantRef()
4545
unset($params['card']['firstName']);
4646
unset($params['card']['lastName']);
4747
$this->request->initialize($params);
48-
var_dump($params['card']);
48+
// var_dump($params['card']);
4949
$this->assertEquals(123, $this->request->getCombinedMerchantRef());
5050
}
51-
5251
}

0 commit comments

Comments
 (0)