Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

All notable changes to this project will be documented in this file.

## [1.2.0] - 2025-11-14
### Added
- Make subscription payment
- Make order payment
- trackers parameter to create subscription
- metadata parameter to create subscription

## [1.1.2] - 2025-04-16
### Added
- added license for order products and subscription
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -272,5 +272,5 @@ catch (\API2Client\Client\APIException $e)

[CHANGELOG]: ./CHANGELOG.md

[version-badge]: https://img.shields.io/badge/version-1.1.2-green.svg
[version-badge]: https://img.shields.io/badge/version-1.2.0-green.svg
[php-version]:https://img.shields.io/static/v1?label=php&message=>=5.3&color=green
7 changes: 5 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
{
"name": "templatemonster/api2-client",
"description": "TemplateMonster API client",
"version": "1.1.2",
"license": "Apache License, Version 2.0",
"version": "1.2.0-pre1",
"authors": [
{
"name": "kolomiets",
"email": "kolomiets.dev@gmail.com"
},
{
"name": "Pavlo Titkov",
"email": "ptitkov@gmail.com"
}
],
"minimum-stability": "dev",
Expand Down
57 changes: 56 additions & 1 deletion src/API2Client/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use API2Client\Entities\OrderCreated;
use API2Client\Entities\OrderItem;
use API2Client\Entities\Subscription;
use API2Client\Entities\SubscriptionResult;
use API2Client\Setters\BillingPortalFactory;
use API2Client\Setters\CustomerPortalFactory;
use API2Client\Setters\OrderCreatedFactory;
Expand Down Expand Up @@ -341,7 +342,7 @@ public function createPaymentSubscription(Subscription $subscription)

/**
* @param $id
* @return Entities\SubscriptionCreated
* @return Entities\SubscriptionResult
* @throws ApiException
*/
public function cancelPaymentSubscription($id)
Expand Down Expand Up @@ -471,4 +472,58 @@ public function getTransactionStatusUrl($transactionId)
$factory = new BillingPortalFactory();
return $factory->create($response->getResult());
}

/**
* Make subscription payment
*
* @param string $subscriptionId
* @param string $paymentMethodId
* @param string $b_token
* @return array
* @throws ApiException
*/
public function makeSubscriptionPayment($subscriptionId, $paymentMethodId, $b_token)
{
$response = $this
->client
->call('orders.makeSubscribePayment', array(
'subscription_id' => $subscriptionId,
'payment_method_id' => $paymentMethodId,
'b_token' => $b_token
), HttpClient::REQUEST_RAW);

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

return $response->getResult();
}

/**
* Make order payment
*
* @param string $orderId
* @param string $paymentMethodId
* @param string $b_token
* @return array
* @throws ApiException
*/
public function makeOrderPayment($orderId, $paymentMethodId, $b_token)
{
$response = $this
->client
->call('orders.makeOrderPayment', array(
'order_id' => $orderId,
'payment_method_id' => $paymentMethodId,
'b_token' => $b_token
), HttpClient::REQUEST_RAW);

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

return $response->getResult();
}


}
2 changes: 1 addition & 1 deletion src/API2Client/Client/APIResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,4 @@ public function getErrorMessage ()
return '';
}

}
}
25 changes: 24 additions & 1 deletion src/API2Client/Entities/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ class Order
*/
protected $cartId;

/**
* @var array
*/
protected $metadata;

/**
* @param float $amount
*/
Expand Down Expand Up @@ -250,7 +255,8 @@ public function toArray()
'trackingInfo' => $this->getTrackingInfo()->toArray(),
'discountInfoList' => array(),
'payment_options' => $this->getPaymentOptions(),
'cartId' => $this->getCartId()
'cartId' => $this->getCartId(),
'metadata' => $this->getMetadata()
);

$data['productInfoList'] = array();
Expand Down Expand Up @@ -305,4 +311,21 @@ public function getCartId()
{
return $this->cartId;
}

/**
* @return array
*/
public function getMetadata()
{
return $this->metadata;
}

/**
* @param array $metadata
*/
public function setMetadata($metadata)
{
$this->metadata = $metadata;
}

}
45 changes: 43 additions & 2 deletions src/API2Client/Entities/OrderCreated.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,13 @@ class OrderCreated
protected $status;

protected $paymentReference;

protected $paymentToken;

protected $transactionId;

protected $b_token;

/**
* @param string $customerId
*/
Expand Down Expand Up @@ -175,6 +179,41 @@ public function setPaymentToken($paymentToken)
$this->paymentToken = $paymentToken;
}

/**
* @return mixed
*/
public function getBToken()
{
return $this->b_token;
}

/**
* @param mixed $b_token
*/
public function setBToken($b_token)
{
$this->b_token = $b_token;
}

/**
* @return mixed
*/
public function getTransactionId()
{
return $this->transactionId;
}

/**
* @param mixed $transactionId
*/
public function setTransactionId($transactionId)
{
$this->transactionId = $transactionId;
}




public function toArray() {
return array(
'customerId' => $this->getCustomerId(),
Expand All @@ -185,6 +224,8 @@ public function toArray() {
'status' => $this->getStatus (),
'payment_reference' => $this->getPaymentReference(),
'payment_token' => $this->getPaymentToken(),
'transactionId' => $this->getTransactionId(),
'b_token' => $this->getBToken(),
);
}
}
}
44 changes: 44 additions & 0 deletions src/API2Client/Entities/Subscription.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,16 @@ class Subscription
/** @var string */
protected $customerId;

/**
* @var array
*/
protected $trackers;

/**
* @var array
*/
protected $metadata;

/**
* @return string
*/
Expand Down Expand Up @@ -708,6 +718,38 @@ public function setCustomerId($customerId)
return $this;
}

/**
* @return array
*/
public function getTrackers()
{
return $this->trackers;
}

/**
* @param array $trackers
*/
public function setTrackers($trackers)
{
$this->trackers = $trackers;
}

/**
* @return array
*/
public function getMetadata()
{
return $this->metadata;
}

/**
* @param array $metadata
*/
public function setMetadata($metadata)
{
$this->metadata = $metadata;
}


/**
* @return array
Expand Down Expand Up @@ -743,6 +785,8 @@ public function toArray()
'customer_id' => $this->getCustomerId(),
'discountInfoList' => array(),
'productInfoList' => array(),
'trackers' => $this->getTrackers(),
'metadata' => $this->getMetadata(),
);

foreach ($this->getProductInfoList() as $productInfo) {
Expand Down
23 changes: 21 additions & 2 deletions src/API2Client/Entities/SubscriptionResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@ class SubscriptionResult
private $messages = array();

private $payment_reference;

private $client_secret;

private $b_token;

/**
* @return mixed
*/
Expand Down Expand Up @@ -128,4 +130,21 @@ public function setClientSecret($client_secret)
return $this;
}

}
/**
* @return mixed
*/
public function getBToken()
{
return $this->b_token;
}

/**
* @param mixed $b_token
*/
public function setBToken($b_token)
{
$this->b_token = $b_token;
}


}
4 changes: 3 additions & 1 deletion src/API2Client/Setters/OrderCreatedFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ public function create ($data)
$orderCreated->setStatus ($this->getValue ('status', $data, ''));
$orderCreated->setPaymentReference($this->getValue ('payment_reference', $data, ''));
$orderCreated->setPaymentToken($this->getValue ('payment_token', $data, ''));
$orderCreated->setTransactionId($this->getValue ('transactionId', $data, ''));
$orderCreated->setBToken($this->getValue ('b_token', $data, ''));

return $orderCreated;
}
}
}
6 changes: 3 additions & 3 deletions src/API2Client/Setters/OrderStatusesFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ class OrderStatusesFactory extends FactoryAbstract implements FactoryInterface
{
/**
* @param array $data
* @return Status
* @return array
*/
public function create ($data)
{
$statusesArrayList = [];
$statusesArrayList = array();

foreach ($data as $status)
{
Expand All @@ -36,4 +36,4 @@ public function create ($data)

return $statusesArrayList;
}
}
}
2 changes: 1 addition & 1 deletion src/API2Client/Setters/SubscriptionResultFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public function create ($data)
$created->setPaymentReference ($this->getValue ('payment_reference', $data, ''));
$created->setClientSecret ($this->getValue ('client_secret', $data, ''));
$created->setStatus ($this->getValue ('status', $data, false));
$created->setBToken($this->getValue ('b_token', $data, ''));

$dataSubscription = $this->getValue ('subscription', $data, array ());

Expand All @@ -37,7 +38,6 @@ public function create ($data)
$created->setMessages ($messages);
}


return $created;
}

Expand Down