Skip to content

Commit f09d137

Browse files
nuhamozainiecleel
authored andcommitted
Added missing wrappers (#11)
* added two methods for HTTP Put requests and update a payment * added two methods for update an invoice and cancel an invoice * refactoring: unnecessary line of code. * edit: description and authors
1 parent ca6f6c3 commit f09d137

File tree

4 files changed

+34
-2
lines changed

4 files changed

+34
-2
lines changed

composer.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
{
22
"name": "moyasar/moyasar-php",
3-
"description": "php api wrapper for moyasar.com",
3+
"description": "PHP wrapper library for Moyasar Payment Service",
44
"type": "library",
55
"authors": [
66
{
77
"name": "Sohib H Algotimel",
88
"email": "s@sgh.sa",
99
"homepage": "https://sgh.sa"
10+
},
11+
{
12+
"name": "Moyasar Dev Team"
1013
}
1114
],
1215
"minimum-stability": "dev",

src/Moyasar/Client.php

+16
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,22 @@ public static function post($request, $options = [])
5757
throw new HttpRequestNotFound($response->getStatusCode() . ' status code returned');
5858
}
5959

60+
public static function put($url,$options = [])
61+
{
62+
$client = new GuzzleHttp\Client();
63+
$data = [
64+
GuzzleHttp\RequestOptions::AUTH => [self::$apiKey, ''],
65+
GuzzleHttp\RequestOptions::FORM_PARAMS => $options,
66+
GuzzleHttp\RequestOptions::DEBUG => false
67+
];
68+
69+
$response = $client->put($url, $data);
70+
if ($response->getStatusCode() == '200' OR '201') {
71+
return $response->getBody()->getContents();
72+
}
73+
throw new HttpRequestNotFound($response->getStatusCode() . ' status code returned');
74+
}
75+
6076

6177
}
6278

src/Moyasar/Invoice.php

+8
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,13 @@ public static function all(){
3535
return json_decode(Client::get("https://api.moyasar.com/v1/invoices"));
3636
}
3737

38+
public static function update($id,$parameter = [] ){
39+
return json_decode(Client::put("https://api.moyasar.com/v1/invoices/$id", $parameter));
40+
}
41+
42+
public static function cancel($id){
43+
return json_decode(Client::put("https://api.moyasar.com/v1/invoices/$id/cancel"));
44+
}
45+
3846

3947
}

src/Moyasar/Payment.php

+6-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
namespace Moyasar;
1010

11-
1211
class Payment
1312
{
1413
const AMOUNT = "amount";
@@ -110,5 +109,11 @@ public static function all(){
110109

111110
}
112111

112+
public static function update($id, $description = ""){
113+
$data = [
114+
self::DESCRIPTION => $description
115+
];
116+
return json_decode(Client::put("https://api.moyasar.com/v1/payments/$id", $data));
117+
}
113118

114119
}

0 commit comments

Comments
 (0)