Skip to content

Commit

Permalink
Added missing wrappers (#11)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
nuhamozaini authored and ecleel committed Jan 28, 2019
1 parent ca6f6c3 commit f09d137
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 2 deletions.
5 changes: 4 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
{
"name": "moyasar/moyasar-php",
"description": "php api wrapper for moyasar.com",
"description": "PHP wrapper library for Moyasar Payment Service",
"type": "library",
"authors": [
{
"name": "Sohib H Algotimel",
"email": "s@sgh.sa",
"homepage": "https://sgh.sa"
},
{
"name": "Moyasar Dev Team"
}
],
"minimum-stability": "dev",
Expand Down
16 changes: 16 additions & 0 deletions src/Moyasar/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,22 @@ public static function post($request, $options = [])
throw new HttpRequestNotFound($response->getStatusCode() . ' status code returned');
}

public static function put($url,$options = [])
{
$client = new GuzzleHttp\Client();
$data = [
GuzzleHttp\RequestOptions::AUTH => [self::$apiKey, ''],
GuzzleHttp\RequestOptions::FORM_PARAMS => $options,
GuzzleHttp\RequestOptions::DEBUG => false
];

$response = $client->put($url, $data);
if ($response->getStatusCode() == '200' OR '201') {
return $response->getBody()->getContents();
}
throw new HttpRequestNotFound($response->getStatusCode() . ' status code returned');
}


}

Expand Down
8 changes: 8 additions & 0 deletions src/Moyasar/Invoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,13 @@ public static function all(){
return json_decode(Client::get("https://api.moyasar.com/v1/invoices"));
}

public static function update($id,$parameter = [] ){
return json_decode(Client::put("https://api.moyasar.com/v1/invoices/$id", $parameter));
}

public static function cancel($id){
return json_decode(Client::put("https://api.moyasar.com/v1/invoices/$id/cancel"));
}


}
7 changes: 6 additions & 1 deletion src/Moyasar/Payment.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

namespace Moyasar;


class Payment
{
const AMOUNT = "amount";
Expand Down Expand Up @@ -110,5 +109,11 @@ public static function all(){

}

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

}

0 comments on commit f09d137

Please sign in to comment.