Skip to content

Commit 6620225

Browse files
ivancalle-sipayzdarcy
authored andcommitted
Merged in HSDK-7 (pull request #7)
HSDK-7 Approved-by: David Francos <davidfrancos@sipay.es> Approved-by: Darcy Zerpa <darcyzerpa@sipay.es>
2 parents a63c3f1 + 95cb8a1 commit 6620225

File tree

6 files changed

+99
-33
lines changed

6 files changed

+99
-33
lines changed

README.md

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,55 @@
33

44
# Instalación
55

6+
Podemos instalarlo de forma manual (Ver "Extracción de código") o utilizando Composer (Ver "Composer").
7+
8+
## Extracción de código
9+
10+
Este paso se omite si se utiliza la instalación via composer.
11+
612
```bash
7-
$ git clone https://github.com/sipay/php-sdk
13+
$ git clone https://github.com/sipay/php-sdk.git
814
```
915

16+
Entonces establecemos la variable "path_autoload" a "<directorio_de_descarga_de_php-sdk>/autoload.php":
17+
18+
```php
19+
$path_autoload = "<directorio_de_descarga_de_php-sdk>/autoload.php";
20+
```
21+
22+
23+
## Composer
24+
25+
Este paso se omite si se utiliza el metodo manual.
26+
27+
Crear archivo composer.json o añadir estos parametros:
28+
29+
```json
30+
{
31+
"repositories": [
32+
{
33+
"type": "vcs",
34+
"url": "https://github.com/sipay/php-sdk.git"
35+
}
36+
],
37+
"require": {
38+
"sipay/php-sdk": "*"
39+
}
40+
}
41+
```
42+
y realizar los siguientes pasos
43+
44+
```bash
45+
$ php -r "readfile('https://getcomposer.org/installer');" | php
46+
$ php composer.phar install
47+
```
48+
49+
Entonces establecemos la variable "path_autoload" a "vendor/autoload.php":
50+
51+
```php
52+
$path_autoload = "vendor/autoload.php";
53+
```
54+
1055

1156
# Quickstart
1257

composer.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"name": "sipay/php-sdk",
3+
"description": "SDK on PHP of operations in Sipay.",
4+
"keywords": ["sipay", "php", "sdk"],
5+
"license": "LLL",
6+
"authors": [
7+
{
8+
"name": "Sipay",
9+
"email": "desarrollo@sipay.es"
10+
}
11+
],
12+
"type": "project",
13+
"require": {
14+
"php": ">=7"
15+
},
16+
"autoload": {
17+
"files": ["src/autoload.php"]
18+
}
19+
}

src/Ecommerce.php

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public function setKey($key)
4848
throw new \Exception('$key must be a string.');
4949
}
5050
if(!preg_match("/^[\w-]{6,32}$/", $key)) {
51-
throw new \Exception('$key don\'t match with pattern.');
51+
throw new \Exception('Invalid key provided: wrong format.');
5252
}
5353
$this->key = $key;
5454
}
@@ -64,7 +64,7 @@ public function setSecret($secret)
6464
throw new \Exception('$secret must be a string.');
6565
}
6666
if(!preg_match("/^[\w-]{6,32}$/", $secret)) {
67-
throw new \Exception('$secret don\'t match with pattern.');
67+
throw new \Exception('Invalid secret provided: wrong format.');
6868
}
6969
$this->secret = $secret;
7070
}
@@ -80,7 +80,7 @@ public function setResource($resource)
8080
throw new \Exception('$resource must be a string.');
8181
}
8282
if(!preg_match("/^[\w-]{6,32}$/", $resource)) {
83-
throw new \Exception('$resource don\'t match with pattern.');
83+
throw new \Exception('Invalid resource provided: wrong format.');
8484
}
8585
$this->resource = $resource;
8686
}
@@ -145,7 +145,7 @@ public function setTimeout($timeout)
145145
}
146146
$timeout = intval($timeout);
147147
if($timeout <= 0) {
148-
throw new \Exception('$timeout must be geater than 0.');
148+
throw new \Exception('$timeout must be greater than 0.');
149149
}
150150
$this->timeout = $timeout;
151151
}
@@ -159,26 +159,27 @@ private function send($payload, $endpoint)
159159

160160
$url = 'https://'.$this->environment.'.sipay.es/mdwr/'.$this->version.'/'.$endpoint;
161161
$data = array(
162-
'key' => $this->key,
163-
'nonce' => "".time(),
164-
'mode' => $this->mode,
165-
'resource' => $this->resource,
166-
'payload' => $payload
162+
'key' => $this->key,
163+
'nonce' => "".time(),
164+
'mode' => $this->mode,
165+
'resource' => $this->resource,
166+
'payload' => $payload
167167
);
168168

169169
$body = json_encode($data);
170170
$signature = hash_hmac($this->mode, $body, $this->secret);
171171

172172
$options = array(
173-
'http' => array(
174-
'header' => "Content-type: application/json\r\nContent-Signature: ".$signature."\r\n",
175-
'method' => 'POST',
176-
'content' => $body,
177-
'timeout' => $this->timeout,
178-
'ignore_errors' => true
179-
),
173+
'http' => array(
174+
'header' => "Content-type: application/json\r\nContent-Signature: ".$signature."\r\n",
175+
'method' => 'POST',
176+
'content' => $body,
177+
'timeout' => $this->timeout,
178+
'ignore_errors' => true
179+
),
180180
);
181-
$context = stream_context_create($options);
181+
182+
$context = stream_context_create($options);
182183
try {
183184
$response_body = file_get_contents($url, false, $context);
184185
} catch (Exception $e) {
@@ -223,12 +224,13 @@ private function send($payload, $endpoint)
223224
$this->logger->info(
224225
'sipay.request', 'request.response', 'I-0002', 'Request Response',
225226
array(
226-
'payload' => $payload,
227-
'endpoint' => $endpoint,
228-
'response' => $response_body)
227+
'payload' => $payload,
228+
'endpoint' => $endpoint,
229+
'response' => $response_body
230+
)
229231
);
230232

231-
return array($body, $response);
233+
return array($body, $response);
232234
}
233235

234236
private function clean_parameters(array $array_options, array $array_schema)
@@ -243,7 +245,7 @@ private function clean_parameters(array $array_options, array $array_schema)
243245
}
244246

245247
if(is_string($option) && isset($schema['pattern']) && !preg_match($schema['pattern'], $option)) {
246-
throw new \Exception("$name don't match with pattern.");
248+
throw new \Exception('Invalid name provided: wrong format.');
247249
}
248250

249251
$options[$name] = $option;
@@ -299,7 +301,7 @@ public function refund($identificator, Amount $amount, array $array_options = ar
299301
$is_tx_id = gettype($identificator) == "string" && preg_match('/^[0-9]{6,22}$/', $identificator);
300302

301303
if (!$is_paymethod && !$is_tx_id) {
302-
throw new \Exception('incorrect $identificator.');
304+
throw new \Exception('Incorrect $identificator.');
303305
}
304306

305307
$array_schema = array(
@@ -347,11 +349,11 @@ public function register(Paymethods\Paymethod $card, string $token)
347349
{
348350

349351
if ($card instanceof Paymethods\StoredCard) {
350-
throw new \Exception('$card can\'t be StoredCard.');
352+
throw new \Exception('$card can\'t be a StoredCard instance.');
351353
}
352354

353355
if(!preg_match('/^[\w-]{6,128}$/', $token)) {
354-
throw new \Exception('$token don\'t match with pattern.');
356+
throw new \Exception('Invalid token provided: wrong format.');
355357
}
356358

357359
$payload = array(
@@ -368,7 +370,7 @@ public function register(Paymethods\Paymethod $card, string $token)
368370
public function card(string $token)
369371
{
370372
if(!preg_match('/^[\w-]{6,128}$/', $token)) {
371-
throw new \Exception('$token don\'t match with pattern.');
373+
throw new \Exception('Invalid token provided: wrong format.');
372374
}
373375

374376
$payload = array(
@@ -383,7 +385,7 @@ public function card(string $token)
383385
public function unregister(string $token)
384386
{
385387
if(!preg_match('/^[\w-]{6,128}$/', $token)) {
386-
throw new \Exception('$token don\'t match with pattern.');
388+
throw new \Exception('Invalid token provided: wrong format.');
387389
}
388390

389391
$payload = array(
@@ -399,7 +401,7 @@ public function cancellation(string $transaction_id)
399401
{
400402

401403
if(!preg_match('/^[0-9]{6,22}$/', $transaction_id)) {
402-
throw new \Exception('$transaction_id don\'t match with pattern.');
404+
throw new \Exception('Invalid transaction_id provided: wrong format.');
403405
}
404406

405407
$payload = array(

src/paymethods/StoredCard.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public function __construct(string $token)
1111
public function set_token(string $token)
1212
{
1313
if(!preg_match("/^[\w-]{6,128}$/", $token)) {
14-
throw new \Exception('$token doesn\'t match with pattern.');
14+
throw new \Exception('Invalid token provided: wrong format.');
1515
}
1616

1717
$this->token = $token;

src/responses/Refund.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class Refund extends Response
1313
public $transaction_id;
1414
public $amount;
1515

16-
public function __construct($request, $response)
16+
public function __construct($request, $response)
1717
{
1818
$payload = $this->set_common($request, $response);
1919
$this->approval = isset($payload['approval']) ? $payload['approval'] : null;
@@ -24,6 +24,7 @@ public function __construct($request, $response)
2424
$this->order = isset($payload['order']) ? $payload['order'] : null;
2525
$this->reference = isset($payload['reconciliation']) ? $payload['reconciliation'] : null;
2626
$this->transaction_id = isset($payload['transaction_id']) ? $payload['transaction_id'] : null;
27+
2728
if(isset($payload['amount']) && isset($payload['currency'])) {
2829
$this->amount = new \Sipay\Amount($payload['amount'], $payload['currency']);
2930
}else{

src/responses/Response.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class Response
1212
public $type;
1313
public $uuid;
1414

15-
protected function set_common($request, $response)
15+
protected function set_common($request, $response)
1616
{
1717
$this->request = $request;
1818
$this->response = $response;
@@ -24,7 +24,6 @@ protected function set_common($request, $response)
2424
$this->type = isset($response['type']) ? $response['type'] : null;
2525
$this->uuid = isset($response['uuid']) ? $response['uuid'] : null;
2626

27-
2827
if($this->code !== "") {
2928
$this->code = intval($this->code);
3029
}

0 commit comments

Comments
 (0)