Skip to content

Commit

Permalink
Payment Subscriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
0legKolomiets committed Jul 2, 2016
1 parent 5012850 commit ea16ae8
Show file tree
Hide file tree
Showing 5 changed files with 815 additions and 0 deletions.
47 changes: 47 additions & 0 deletions src/API2Client/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,16 @@

use API2Client\Client\APIClient;
use API2Client\Client\Http\HttpClient;
use API2Client\Entities\Subscription;
use API2Client\Setters\OrderCreatedFactory;
use API2Client\Setters\OrderCurrencyFactory;
use API2Client\Setters\OrderItemFactory;
use API2Client\Setters\OrderLinksFactory;
use API2Client\Setters\OrderStatusesFactory;
use API2Client\Setters\OrderPaymentFactory;
use API2Client\Setters\OrderStatusFactory;
use API2Client\Setters\SubscriptionCreatedFactory;
use API2Client\Setters\SubscriptionResultFactory;
use API2Client\Setters\TemplateFactory;

/**
Expand Down Expand Up @@ -314,4 +317,48 @@ public function getCurrencies ()

return $result;
}

/**
* @param Subscription $subscription
* @return Entities\SubscriptionResult
* @throws ApiException
*/
public function createPaymentSubscription (Subscription $subscription)
{
$response = $this
->client
->call ('orders.subscribe', $subscription->toArray (), HttpClient::REQUEST_RAW);

if (!$response->isSuccess ())
{
throw new ApiException ($response->getErrorMessage ());
}

$subscription = new SubscriptionResultFactory();

return $subscription
->create ($response->getResult ());
}

/**
* @param $id
* @return Entities\SubscriptionCreated
* @throws ApiException
*/
public function cancelPaymentSubscription ($id)
{
$response = $this
->client
->call ('orders.unsubscribe', array ('id' => $id), HttpClient::REQUEST_RAW);

if (!$response->isSuccess ())
{
throw new ApiException ($response->getErrorMessage ());
}

$subscription = new SubscriptionResultFactory ();

return $subscription
->create ($response->getResult ());
}
}
1 change: 1 addition & 0 deletions src/API2Client/Client/APIClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public function call ($apiMethod, $params = array (), $method = HttpClient::REQU
{
$resultContent = $this->httpClient->request ($this->getAuthorizedUrl ($apiMethod), $params, $method);


$response = new APIResponse ();
$response->create ($resultContent);

Expand Down
Loading

0 comments on commit ea16ae8

Please sign in to comment.