├── tests
├── stubs
│ └── privatekey.stub
├── FactoryTest.php
└── RequestTest.php
├── .gitignore
├── src
└── Borica
│ ├── Exceptions
│ ├── LengthException.php
│ └── InvalidParameterException.php
│ ├── KeyReader.php
│ ├── Factory.php
│ ├── Response.php
│ └── Request.php
├── .travis.yml
├── phpunit.xml
├── composer.json
└── README.md
/tests/stubs/privatekey.stub:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | vendor/
2 | .idea/
3 |
4 | composer.lock
--------------------------------------------------------------------------------
/src/Borica/Exceptions/LengthException.php:
--------------------------------------------------------------------------------
1 |
6 |
7 |
8 |
9 | tests/
10 |
11 |
12 |
13 |
14 |
15 | src/
16 |
17 |
18 |
--------------------------------------------------------------------------------
/composer.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "mirovit/borica-api",
3 | "description": "Package that enables the communication with BORICA via their API",
4 | "license": "MIT",
5 | "authors": [
6 | {
7 | "name": "Miroslav Vitanov",
8 | "email": "mvvitanov@gmail.com"
9 | }
10 | ],
11 | "require": {
12 | "nesbot/carbon": "^1.21"
13 | },
14 | "require-dev": {
15 | "phpunit/phpunit": "4.8.*",
16 | "mockery/mockery": "^1.0"
17 | },
18 | "autoload": {
19 | "psr-4": {
20 | "Mirovit\\": "src/"
21 | }
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/src/Borica/Factory.php:
--------------------------------------------------------------------------------
1 | request = $request;
19 | $this->response = $response;
20 | }
21 |
22 | /**
23 | * Make a request to Borica.
24 | *
25 | * @return Request
26 | */
27 | public function request()
28 | {
29 | return $this->request;
30 | }
31 |
32 | /**
33 | * Parse a response from Borica.
34 | *
35 | * @param string $message
36 | * @return Response
37 | */
38 | public function response($message = null)
39 | {
40 | if(!empty($message))
41 | {
42 | return $this->response->parse($message);
43 | }
44 |
45 | return $this->response;
46 | }
47 | }
--------------------------------------------------------------------------------
/tests/FactoryTest.php:
--------------------------------------------------------------------------------
1 | request = m::mock(Request::class);
18 | $this->response = m::mock(Response::class);
19 |
20 | $this->factory = new Factory(
21 | $this->request,
22 | $this->response
23 | );
24 | }
25 |
26 | /** @test */
27 | public function it_provides_access_to_the_request()
28 | {
29 | $this->assertInstanceOf(Request::class, $this->factory->request());
30 | }
31 |
32 | /** @test */
33 | public function it_provides_access_to_the_response()
34 | {
35 | $this->assertInstanceOf(Response::class, $this->factory->response());
36 | }
37 |
38 | /** @test */
39 | public function it_calls_the_parse_method_when_response_has_param()
40 | {
41 | $this->response
42 | ->shouldReceive('parse')
43 | ->once()
44 | ->andReturnSelf();
45 |
46 | $this->assertInstanceOf(Response::class, $this->factory->response('123'));
47 | }
48 |
49 | public function tearDown()
50 | {
51 | m::close();
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # BORICA API
2 |
3 | This is a simple implementation of the BORICA API for adding payments with their service.
4 |
5 | # Instalation
6 |
7 | Pull from [Composer](https://getcomposer.org/):
8 |
9 | ```
10 | composer require mirovit/borica-api
11 | ```
12 |
13 | # How to use
14 |
15 | One way would be to new up a version of `Mirovit\Borica\Factory`, which accepts `Mirovit\Borica\Request` and `Mirovit\Borica\Response` as constructor arguments. Or just use the the Request and Response classes individually.
16 |
17 | The Request as its name suggests is responsible for generating the URLs for request to the Borica API - possible requests are: register transaction, check status of transaction, register delayed transaction request, complete a delayed transaction request, reverse delayed transaction request and reverse a partially or the full sum from a registered transaction.
18 |
19 | ```php
20 | ', '', '', '', ''),
26 | new Response('')
27 | );
28 | ```
29 |
30 | ## Registering of a transaction
31 | ```php
32 | $factory->request()
33 | ->amount('1') // 1 EUR
34 | ->orderID(1) // Unique identifier in your system
35 | ->description('testing the process') // Short description of the purchase (up to 125 chars)
36 | ->currency('EUR') // The currency of the payment
37 | ->register(); // Type of the request
38 | ```
39 |
40 | ## Check status of a transaction
41 | ```php
42 | $factory->request()
43 | ->amount('1') // 1 EUR
44 | ->orderID(1) // Unique identifier in your system
45 | ->description('testing the process') // Short description of the purchase (up to 125 chars)
46 | ->currency('EUR') // The currency of the payment
47 | ->status(); // Type of the request
48 | ```
49 |
50 | ## Reverse a transaction
51 | ```php
52 | $factory->request()
53 | ->amount('1') // 1 EUR - partial reversal (amount less than the original), full reversal the original amount
54 | ->orderID(1) // Unique identifier in your system
55 | ->reverse(); // Type of the request
56 | ```
57 |
58 | # Using with Laravel 5
59 |
60 | Create a service provider as the one below and register it with the app.
61 | You can either add it to the `config/app.php` or register it in `Providers/AppServiceProvider.php`.
62 |
63 | ```
64 | app->bind(Request::class, function(){
84 | return new Request(env('BORICA_TERMINAL_ID'), 'path/to/private.key', '', app()->getLocale());
85 | });
86 |
87 | $this->app->bind(Response::class, function(){
88 | return new Response('path/to/public.cer');
89 | });
90 |
91 | $this->app->bind(Factory::class, function(){
92 | return new Factory(app(Request::class), app(Response::class));
93 | }, true);
94 | }
95 | }
96 | ```
97 |
98 | # Contributing
99 |
100 | If you'd like to contribute, feel free to send a pull request!
101 |
--------------------------------------------------------------------------------
/src/Borica/Response.php:
--------------------------------------------------------------------------------
1 | publicCertificate = $publicCertificate;
28 | $this->useFileKeyReader = $useFileKeyReader;
29 | }
30 |
31 | public function parse($message)
32 | {
33 | $message = base64_decode($message);
34 |
35 | $response = [
36 | self::TRANSACTION_CODE => substr($message, 0, 2),
37 | self::TRANSACTION_TIME => substr($message, 2, 14),
38 | self::AMOUNT => substr($message, 16, 12),
39 | self::TERMINAL_ID => substr($message, 28, 8),
40 | self::ORDER_ID => substr($message, 36, 15),
41 | self::RESPONSE_CODE => substr($message, 51, 2),
42 | self::PROTOCOL_VERSION => substr($message, 53, 3),
43 | self::SIGN => substr($message, 56, 128),
44 | self::SIGNATURE_OK => $this->verifySignature($message, substr($message, 56, 128)),
45 | ];
46 |
47 | $this->response = $response;
48 |
49 | return $this;
50 | }
51 |
52 | public function transactionCode()
53 | {
54 | return $this->response[self::TRANSACTION_CODE];
55 | }
56 |
57 | public function transactionTime()
58 | {
59 | return Carbon::createFromFormat('YmdHms', $this->response[self::TRANSACTION_TIME]);
60 | }
61 |
62 | public function amount()
63 | {
64 | return (float)$this->response[self::AMOUNT] / 100;
65 | }
66 |
67 | public function terminalID()
68 | {
69 | return $this->response[self::TERMINAL_ID];
70 | }
71 |
72 | public function orderID()
73 | {
74 | return trim($this->response[self::ORDER_ID]);
75 | }
76 |
77 | public function responseCode()
78 | {
79 | return $this->response[self::RESPONSE_CODE];
80 | }
81 |
82 | public function protocolVersion()
83 | {
84 | return $this->response[self::PROTOCOL_VERSION];
85 | }
86 |
87 | public function signatureOk()
88 | {
89 | return $this->response[self::SIGNATURE_OK];
90 | }
91 |
92 | public function isSuccessful()
93 | {
94 | return $this->responseCode() === '00';
95 | }
96 |
97 | public function notSuccessful()
98 | {
99 | return !$this->isSuccessful();
100 | }
101 |
102 | /**
103 | * Verify the returned response.
104 | *
105 | * @param $message
106 | * @param $signature
107 | * @return mixed
108 | */
109 | public function verifySignature($message, $signature)
110 | {
111 | $cert = $this->getCertificate();
112 |
113 | $pubkeyid = openssl_get_publickey($cert);
114 |
115 | $verify = openssl_verify(substr($message, 0, strlen($message) - 128), $signature, $pubkeyid);
116 |
117 | openssl_free_key($pubkeyid);
118 |
119 | return $verify;
120 | }
121 |
122 | /**
123 | * Read the private key contents and return it.
124 | *
125 | * @return string
126 | */
127 | public function getCertificate()
128 | {
129 | if ($this->useFileKeyReader) {
130 | return $this->readKey($this->publicCertificate);
131 | }
132 |
133 | return $this->publicCertificate;
134 | }
135 | }
--------------------------------------------------------------------------------
/src/Borica/Request.php:
--------------------------------------------------------------------------------
1 | terminalID = $terminalID;
41 | $this->privateKey = $privateKey;
42 | $this->privateKeyPassword = $privateKeyPassword;
43 | $this->useFileKeyReader = $useFileKeyReader;
44 | $this->language = strtoupper($language);
45 | $this->debug = $debug;
46 | }
47 |
48 | /**
49 | * Register a transaction with Borica.
50 | *
51 | * @param string $protocolVersion
52 | * @param string $oneTimeTicket
53 | * @return string
54 | */
55 | public function register($protocolVersion = '1.1', $oneTimeTicket = null)
56 | {
57 | $message = $this->getBaseMessage(self::REGISTER_TRANSACTION, $protocolVersion);
58 |
59 | if ($protocolVersion == '2.0') {
60 | $message[] = str_pad($oneTimeTicket, 6);
61 | }
62 |
63 | return $this->generateURL($message, 'registerTransaction');
64 | }
65 |
66 | /**
67 | * Check the status of a transaction with Borica.
68 | *
69 | * @param string $protocolVersion
70 | * @return string
71 | */
72 | public function status($protocolVersion = '1.1')
73 | {
74 | $message = $this->getBaseMessage(self::REGISTER_TRANSACTION, $protocolVersion);
75 |
76 | return $this->generateURL($message, 'transactionStatusReport');
77 | }
78 |
79 | /**
80 | * Register a delayed request.
81 | *
82 | * @param string $protocolVersion
83 | * @return string
84 | */
85 | public function registerDelayedRequest($protocolVersion = '1.1')
86 | {
87 | $message = $this->getBaseMessage(self::DELAYED_AUTHORIZATION_REQUEST, $protocolVersion);
88 |
89 | return $this->generateURL($message);
90 | }
91 |
92 | /**
93 | * Complete an already registered transaction.
94 | *
95 | * @param string $protocolVersion
96 | * @return string
97 | */
98 | public function completeDelayedRequest($protocolVersion = '1.1')
99 | {
100 | $message = $this->getBaseMessage(self::DELAYED_AUTHORIZATION_COMPLETE, $protocolVersion);
101 |
102 | return $this->generateURL($message);
103 | }
104 |
105 | /**
106 | * Cancel already registered delayed request.
107 | *
108 | * @param string $protocolVersion
109 | * @return string
110 | */
111 | public function reverseDelayedRequest($protocolVersion = '1.1')
112 | {
113 | $message = $this->getBaseMessage(self::DELAYED_AUTHORIZATION_REVERSAL, $protocolVersion);
114 |
115 | return $this->generateURL($message);
116 | }
117 |
118 | /**
119 | * Reverse a payment.
120 | *
121 | * @param string $protocolVersion
122 | * @return string
123 | */
124 | public function reverse($protocolVersion = '1.1')
125 | {
126 | $message = $this->getBaseMessage(self::REVERSAL, $protocolVersion);
127 |
128 | return $this->generateURL($message);
129 | }
130 |
131 | public function getDate()
132 | {
133 | return date('YmdHis');
134 | }
135 |
136 | public function getAmount()
137 | {
138 | $this->validateAmount($this->amount);
139 |
140 | return str_pad($this->amount, 12, '0', STR_PAD_LEFT);
141 | }
142 |
143 | public function getTerminalID()
144 | {
145 | return $this->terminalID;
146 | }
147 |
148 | public function getOrderID()
149 | {
150 | $this->validateOrderID($this->orderID);
151 |
152 | return str_pad(substr($this->orderID, 0, 15), 15);
153 | }
154 |
155 | public function getDescription()
156 | {
157 | $this->validateDescription($this->description);
158 |
159 | return str_pad(substr($this->description, 0, 125), 125);
160 | }
161 |
162 | public function getLanguage()
163 | {
164 | return ($this->language == 'BG' || $this->language == 'EN') ? $this->language : 'EN';
165 | }
166 |
167 | public function getCurrency()
168 | {
169 | return $this->currency;
170 | }
171 |
172 | public function transactionCode($code)
173 | {
174 | $this->transactionCode = $code;
175 |
176 | return $this;
177 | }
178 |
179 | public function amount($amount)
180 | {
181 | $this->validateAmount($amount);
182 |
183 | $this->amount = $amount * 100;
184 |
185 | return $this;
186 | }
187 |
188 | public function orderID($id)
189 | {
190 | $this->validateOrderID($id);
191 |
192 | $this->orderID = $id;
193 |
194 | return $this;
195 | }
196 |
197 | public function description($desc)
198 | {
199 | $this->validateDescription($desc);
200 |
201 | $this->description = $desc;
202 |
203 | return $this;
204 | }
205 |
206 | public function currency($currency)
207 | {
208 | $this->currency = strtoupper($currency);
209 |
210 | return $this;
211 | }
212 |
213 | /**
214 | * Ensure that the protocol version is correct.
215 | *
216 | * @param $protocolVersion
217 | * @return bool
218 | */
219 | public function getProtocolVersion($protocolVersion)
220 | {
221 | if(in_array($protocolVersion, self::SUPPORTED_VERSIONS)) {
222 | return $protocolVersion;
223 | }
224 |
225 | return '1.1';
226 | }
227 |
228 | /**
229 | * Get the proper gateway url.
230 | *
231 | * @return string
232 | */
233 | public function getGatewayURL()
234 | {
235 | return (bool)$this->debug ? $this->testGatewayURL : $this->gatewayURL;
236 | }
237 |
238 | /**
239 | * Generate the request URL for Borica.
240 | *
241 | * @param $message
242 | * @param string $type
243 | * @return string
244 | */
245 | public function generateURL($message, $type = 'manageTransaction')
246 | {
247 | $message = $this->signMessage($message);
248 |
249 | return "{$this->getGatewayURL()}{$type}?eBorica=" . urlencode(base64_encode($message));
250 | }
251 |
252 |
253 | /**
254 | * Read the private key contents and return it.
255 | *
256 | * @return string
257 | */
258 | public function getPrivateKey()
259 | {
260 | if ($this->useFileKeyReader) {
261 | return $this->readKey($this->privateKey);
262 | }
263 |
264 | return $this->privateKey;
265 | }
266 |
267 | /**
268 | * Sign the message with the private key of the merchant.
269 | *
270 | * @param $message
271 | * @return mixed
272 | */
273 | public function signMessage($message)
274 | {
275 | if(is_array($message)) {
276 | $message = implode('', $message);
277 | }
278 |
279 | $signature = null;
280 |
281 | $pkeyid = openssl_pkey_get_private($this->getPrivateKey(), $this->privateKeyPassword);
282 | openssl_sign($message, $signature, $pkeyid);
283 | openssl_free_key($pkeyid);
284 |
285 | return $message . $signature;
286 | }
287 |
288 | /**
289 | * Get the base message structure.
290 | *
291 | * @param $messageType
292 | * @param string $protocolVersion
293 | * @return array
294 | */
295 | protected function getBaseMessage($messageType, $protocolVersion = '1.1')
296 | {
297 | $protocolVersion = $this->getProtocolVersion($protocolVersion);
298 |
299 | $message = [
300 | $messageType,
301 | $this->getDate(),
302 | $this->getAmount(),
303 | $this->getTerminalID(),
304 | $this->getOrderID(),
305 | $this->getDescription(),
306 | $this->getLanguage(),
307 | $protocolVersion,
308 | ];
309 |
310 | if ($protocolVersion != '1.0') {
311 | $message[] = $this->getCurrency();
312 | }
313 |
314 | return $message;
315 | }
316 |
317 | /**
318 | * @param $amount
319 | */
320 | private function validateAmount($amount)
321 | {
322 | if (!is_numeric($amount)) {
323 | throw new InvalidParameterException('The amount should be a number!');
324 | }
325 | }
326 |
327 | /**
328 | * @param string $desc
329 | */
330 | private function validateDescription($desc)
331 | {
332 | $descLength = strlen($desc);
333 |
334 | if ($descLength < 1 || $descLength > 125) {
335 | throw new LengthException('The description of the request should be between 1 and 125 symbols.');
336 | }
337 | }
338 |
339 | /**
340 | * @param $id
341 | */
342 | private function validateOrderID($id)
343 | {
344 | $idLength = strlen($id);
345 |
346 | if ($idLength < 1 || $idLength > 15) {
347 | throw new LengthException('The order id should be between 1 and 15 symbols.');
348 | }
349 | }
350 | }
351 |
--------------------------------------------------------------------------------
/tests/RequestTest.php:
--------------------------------------------------------------------------------
1 | request = new Request(12345678, 'tests/stubs/privatekey.stub');
15 | }
16 |
17 | /** @test */
18 | public function it_registers_a_transaction_with_protocol_1_0()
19 | {
20 | $url = $this->request
21 | ->amount(1)
22 | ->orderID(1)
23 | ->description('testing the process')
24 | ->currency('EUR')
25 | ->register('1.0');
26 |
27 | $expected = $this->request->getGatewayURL() .
28 | 'registerTransaction?eBorica=' .
29 | Request::REGISTER_TRANSACTION .
30 | $this->request->getDate() .
31 | $this->request->getAmount() .
32 | $this->request->getTerminalID() .
33 | $this->request->getOrderID() .
34 | $this->request->getDescription() .
35 | $this->request->getLanguage() .
36 | '1.0';
37 |
38 | $this->assertSame(
39 | $expected,
40 | $url
41 | );
42 | }
43 |
44 | /** @test */
45 | public function it_registers_a_transaction_with_protocol_1_1()
46 | {
47 | $url = $this->request
48 | ->amount(1)
49 | ->orderID(1)
50 | ->description('testing the process')
51 | ->currency('EUR')
52 | ->register('1.1');
53 |
54 | $expected = $this->request->getGatewayURL() .
55 | 'registerTransaction?eBorica=' .
56 | Request::REGISTER_TRANSACTION .
57 | $this->request->getDate() .
58 | $this->request->getAmount() .
59 | $this->request->getTerminalID() .
60 | $this->request->getOrderID() .
61 | $this->request->getDescription() .
62 | $this->request->getLanguage() .
63 | '1.1' .
64 | $this->request->getCurrency();
65 |
66 | $this->assertSame(
67 | $expected,
68 | $url
69 | );
70 | }
71 |
72 | /** @test */
73 | public function it_registers_a_transaction_with_protocol_2_0()
74 | {
75 | $url = $this->request
76 | ->amount(1)
77 | ->orderID(1)
78 | ->description('testing the process')
79 | ->currency('EUR')
80 | ->register('2.0', '');
81 |
82 | $expected = $this->request->getGatewayURL() .
83 | 'registerTransaction?eBorica=' .
84 | Request::REGISTER_TRANSACTION .
85 | $this->request->getDate() .
86 | $this->request->getAmount() .
87 | $this->request->getTerminalID() .
88 | $this->request->getOrderID() .
89 | $this->request->getDescription() .
90 | $this->request->getLanguage() .
91 | '2.0' .
92 | $this->request->getCurrency() .
93 | str_pad('', 6);
94 |
95 | $this->assertSame(
96 | $expected,
97 | $url
98 | );
99 | }
100 |
101 | /** @test */
102 | public function it_checks_status()
103 | {
104 | $protocol_version = '2.0';
105 |
106 | $url = $this->request
107 | ->amount(1)
108 | ->orderID(1)
109 | ->description('testing the process')
110 | ->currency('EUR')
111 | ->status($protocol_version);
112 |
113 | $expected = $this->request->getGatewayURL() .
114 | 'transactionStatusReport?eBorica=' .
115 | Request::REGISTER_TRANSACTION .
116 | $this->request->getDate() .
117 | $this->request->getAmount() .
118 | $this->request->getTerminalID() .
119 | $this->request->getOrderID() .
120 | $this->request->getDescription() .
121 | $this->request->getLanguage() .
122 | $protocol_version .
123 | $this->request->getCurrency();
124 |
125 | $this->assertSame(
126 | $expected,
127 | $url
128 | );
129 | }
130 |
131 | /** @test */
132 | public function it_reverses_a_transaction()
133 | {
134 | $protocol_version = '1.1';
135 |
136 | $url = $this->request
137 | ->amount(1)
138 | ->orderID(1)
139 | ->description('testing the process')
140 | ->currency('EUR')
141 | ->reverse($protocol_version);
142 |
143 | $expected = $this->request->getGatewayURL() .
144 | 'manageTransaction?eBorica=' .
145 | Request::REVERSAL .
146 | $this->request->getDate() .
147 | $this->request->getAmount() .
148 | $this->request->getTerminalID() .
149 | $this->request->getOrderID() .
150 | $this->request->getDescription() .
151 | $this->request->getLanguage() .
152 | $protocol_version .
153 | $this->request->getCurrency();
154 |
155 | $this->assertSame(
156 | $expected,
157 | $url
158 | );
159 | }
160 |
161 | /** @test */
162 | public function it_registeres_a_delayed_transaction()
163 | {
164 | $protocol_version = '1.1';
165 |
166 | $url = $this->request
167 | ->amount(1)
168 | ->orderID(1)
169 | ->description('testing the process')
170 | ->currency('EUR')
171 | ->registerDelayedRequest($protocol_version);
172 |
173 | $expected = $this->request->getGatewayURL() .
174 | 'manageTransaction?eBorica=' .
175 | Request::DELAYED_AUTHORIZATION_REQUEST .
176 | $this->request->getDate() .
177 | $this->request->getAmount() .
178 | $this->request->getTerminalID() .
179 | $this->request->getOrderID() .
180 | $this->request->getDescription() .
181 | $this->request->getLanguage() .
182 | $protocol_version .
183 | $this->request->getCurrency();
184 |
185 | $this->assertSame(
186 | $expected,
187 | $url
188 | );
189 | }
190 |
191 | /** @test */
192 | public function it_completes_a_delayed_transaction()
193 | {
194 | $protocol_version = '1.1';
195 |
196 | $url = $this->request
197 | ->amount(1)
198 | ->orderID(1)
199 | ->description('testing the process')
200 | ->currency('EUR')
201 | ->completeDelayedRequest($protocol_version);
202 |
203 | $expected = $this->request->getGatewayURL() .
204 | 'manageTransaction?eBorica=' .
205 | Request::DELAYED_AUTHORIZATION_COMPLETE .
206 | $this->request->getDate() .
207 | $this->request->getAmount() .
208 | $this->request->getTerminalID() .
209 | $this->request->getOrderID() .
210 | $this->request->getDescription() .
211 | $this->request->getLanguage() .
212 | $protocol_version .
213 | $this->request->getCurrency();
214 |
215 | $this->assertSame(
216 | $expected,
217 | $url
218 | );
219 | }
220 |
221 | /** @test */
222 | public function it_reverses_a_delayed_transaction()
223 | {
224 | $protocol_version = '1.1';
225 |
226 | $url = $this->request
227 | ->amount(1)
228 | ->orderID(1)
229 | ->description('testing the process')
230 | ->currency('EUR')
231 | ->reverseDelayedRequest($protocol_version);
232 |
233 | $expected = $this->request->getGatewayURL() .
234 | 'manageTransaction?eBorica=' .
235 | Request::DELAYED_AUTHORIZATION_REVERSAL .
236 | $this->request->getDate() .
237 | $this->request->getAmount() .
238 | $this->request->getTerminalID() .
239 | $this->request->getOrderID() .
240 | $this->request->getDescription() .
241 | $this->request->getLanguage() .
242 | $protocol_version .
243 | $this->request->getCurrency();
244 |
245 | $this->assertSame(
246 | $expected,
247 | $url
248 | );
249 | }
250 |
251 | /** skip for now */
252 | public function it_pays_profit()
253 | {
254 | $url = $this->request
255 | ->amount(1)
256 | ->orderID(1)
257 | ->payProfit();
258 |
259 | $expected = $this->request->getGatewayURL() .
260 | 'manageTransaction?eBorica=' .
261 | Request::PAY_PROFIT .
262 | $this->request->getAmount() .
263 | $this->request->getOrderID();
264 |
265 | $this->assertSame(
266 | $expected,
267 | $url
268 | );
269 | }
270 |
271 | /** @test */
272 | public function it_gets_correct_terminal_id()
273 | {
274 | $this->assertSame(12345678, $this->request->getTerminalID());
275 | }
276 |
277 | /** @test */
278 | public function it_sets_correct_value_for_amount()
279 | {
280 | $this->request->amount(1);
281 | $this->assertSame('000000000100', $this->request->getAmount());
282 | }
283 |
284 | /** @test */
285 | public function it_sets_correct_value_for_order_id()
286 | {
287 | $this->request->orderID(1);
288 | $this->assertSame(str_pad('1', 15), $this->request->getOrderID());
289 | }
290 |
291 | /** @test */
292 | public function it_sets_correct_value_for_description()
293 | {
294 | $this->request->description('testing the process');
295 | $this->assertSame(str_pad('testing the process', 125), $this->request->getDescription());
296 | }
297 |
298 | /** @test */
299 | public function it_sets_correct_value_for_currency()
300 | {
301 | $this->request->currency('eUr');
302 | $this->assertSame('EUR', $this->request->getCurrency());
303 | }
304 |
305 | /** @test */
306 | public function it_verifies_the_protocol_version()
307 | {
308 | $this->assertSame('1.0', $this->request->getProtocolVersion('1.0'));
309 | $this->assertSame('1.1', $this->request->getProtocolVersion('1.1'));
310 | $this->assertSame('2.0', $this->request->getProtocolVersion('2.0'));
311 |
312 | $this->assertNotSame('123', $this->request->getProtocolVersion('123'));
313 | }
314 |
315 | /**
316 | * @test
317 | * @expectedException \Mirovit\Borica\Exceptions\InvalidParameterException
318 | */
319 | public function it_validates_amount()
320 | {
321 | $this->request->amount('not-a-number-amount');
322 | }
323 |
324 | /**
325 | * @test
326 | * @expectedException \Mirovit\Borica\Exceptions\LengthException
327 | */
328 | public function it_validates_description()
329 | {
330 | $this->request->description('');
331 | }
332 |
333 | /**
334 | * @test
335 | * @expectedException \Mirovit\Borica\Exceptions\LengthException
336 | */
337 | public function it_validates_order_id()
338 | {
339 | $this->request->orderID(12345678910111213);
340 | }
341 | }
342 |
343 | function base64_encode($str)
344 | {
345 | return $str;
346 | }
347 |
348 | function urlencode($str)
349 | {
350 | return $str;
351 | }
352 |
353 | function openssl_pkey_get_private($privateKey, $privateKeyPassword)
354 | {
355 | return null;
356 | }
357 |
358 | function openssl_sign($message, $signature, $pkeyid)
359 | {
360 | return null;
361 | }
362 |
363 | function openssl_free_key($pkId)
364 | {
365 | return null;
366 | }
--------------------------------------------------------------------------------