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
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"docs": "https://openapi.tpay.com"
},
"require": {
"php": ">=5.6.0",
"php": ">=7.1",
"ext-curl": "*",
"ext-fileinfo": "*",
"ext-json": "*",
Expand Down
15 changes: 15 additions & 0 deletions examples/Notifications/AllNotificationsExample.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Tpay\OpenApi\Model\Objects\NotificationBody\BlikAliasUnregister;
use Tpay\OpenApi\Model\Objects\NotificationBody\BlikAliasUpdated;
use Tpay\OpenApi\Model\Objects\NotificationBody\MarketplaceTransaction;
use Tpay\OpenApi\Model\Objects\NotificationBody\Recurring;
use Tpay\OpenApi\Model\Objects\NotificationBody\Tokenization;
use Tpay\OpenApi\Model\Objects\NotificationBody\TokenUpdate;
use Tpay\OpenApi\Model\Objects\Objects;
Expand Down Expand Up @@ -130,6 +131,20 @@ public function getVerifiedNotification()
exit('TRUE');
}

if ($notification instanceof Recurring) {
// Notification about successful recurring registered

$recurringId = $notification->recurringId->getValue();
// The above example will check the notification and return the value of recurring id

$transactionId = $notification->transactionId->getValue();
// The above example will check the notification and return the value of received transaction id field
// You can access any notification field by $notification->fieldName

// $recurringProcessor->process($notification)
exit('{"result":true}');
}

// Ignore and silence other notification types if not expected
http_response_code(404);
exit('FALSE');
Expand Down
5 changes: 5 additions & 0 deletions src/Api/ApiAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,11 @@ protected function addQueryFields($requestUrl, $queryFields)
return $requestUrl;
}

protected function isProductionMode()
{
return true === $this->productionMode;
}

private function checkResponse()
{
$responseCode = $this->getHttpResponseCode();
Expand Down
87 changes: 87 additions & 0 deletions src/Api/Recurring/RecurringApi.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<?php

namespace Tpay\OpenApi\Api\Recurring;

use Tpay\OpenApi\Api\ApiAction;
use Tpay\OpenApi\Model\Fields\Recurring\PaymentInstrument\PaymentType;
use Tpay\OpenApi\Model\Objects\RequestBody\Recurring;
use Tpay\OpenApi\Model\Objects\RequestBody\UpdatePaymentInstrument;
use UnexpectedValueException;

class RecurringApi extends ApiAction
{
private const PAYMENT_INSTRUMENT_FIELD = 'paymentInstrument';
private const PAYMENT_TYPE_FIELD = 'paymentType';

/** @param array $queryFields */
public function getRecurring($queryFields = [])
{
$requestUrl = $this->addQueryFields('/recurring', $queryFields);

return $this->run(static::GET, $requestUrl);
}

/** @param string $recurringId */
public function getRecurringById($recurringId)
{
return $this->run(static::GET, sprintf('/recurring/%s', $recurringId));
}

/**
* @param string $recurringId
* @param array $queryFields
*/
public function getTransactionsByRecurringId($recurringId, $queryFields = [])
{
$requestUrl = $this->addQueryFields(sprintf('/recurring/%s/transactions', $recurringId), $queryFields);

return $this->run(static::GET, $requestUrl);
}

/** @param array $fields */
public function createRecurring($fields)
{
$this->validateProductionPaymentType($fields);

return $this->run(static::POST, '/recurring', $fields, new Recurring());
}

/** @param string $recurringId */
public function cancelRecurring($recurringId)
{
return $this->run(static::POST, sprintf('/recurring/%s/cancel', $recurringId));
}

/** @param string $recurringId */
public function retryRecurring($recurringId)
{
return $this->run(static::POST, sprintf('/recurring/%s/retry', $recurringId));
}

/** @param string $recurringId */
public function updatePaymentInstrument($fields, $recurringId)
{
return $this->run(
static::POST,
sprintf('/recurring/%s/payment_instrument', $recurringId),
$fields,
new UpdatePaymentInstrument()
);
}

/** @param array $fields */
private function validateProductionPaymentType($fields)
{
if (
!$this->isProductionMode()
|| !isset($fields[self::PAYMENT_INSTRUMENT_FIELD][self::PAYMENT_TYPE_FIELD])
|| PaymentType::TEST !== $fields[self::PAYMENT_INSTRUMENT_FIELD][self::PAYMENT_TYPE_FIELD]
) {
return;
}

throw new UnexpectedValueException(
sprintf('paymentType "%s" is not allowed in production mode', PaymentType::TEST)
);
}
}
20 changes: 20 additions & 0 deletions src/Api/TpayApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Tpay\OpenApi\Api\Authorization\AuthorizationApi;
use Tpay\OpenApi\Api\Blik\BlikApi;
use Tpay\OpenApi\Api\Collect\CollectApi;
use Tpay\OpenApi\Api\Recurring\RecurringApi;
use Tpay\OpenApi\Api\Refunds\RefundsApi;
use Tpay\OpenApi\Api\Reports\ReportsApi;
use Tpay\OpenApi\Api\Transactions\TransactionsApi;
Expand All @@ -28,6 +29,9 @@ class TpayApi
/** @var null|CollectApi */
private $collect;

/** @var null|RecurringApi */
private $recurring;

/** @var null|RefundsApi */
private $refunds;

Expand Down Expand Up @@ -147,6 +151,22 @@ public function authorization()
return $this->authorization;
}

/** @return RecurringApi */
public function recurring()
{
$this->authorize();
if (null === $this->recurring) {
$this->recurring = (new RecurringApi($this->token, $this->productionMode))
->overrideApiUrl($this->apiUrl);

if ($this->clientName) {
$this->recurring->setClientName($this->clientName);
}
}

return $this->recurring;
}

/** @return RefundsApi */
public function refunds()
{
Expand Down
11 changes: 11 additions & 0 deletions src/Factory/ArrayObjectFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
use Tpay\OpenApi\Model\Objects\Merchant\ContactPerson;
use Tpay\OpenApi\Model\Objects\Merchant\PointOfSale as MerchantPointOfSale;
use Tpay\OpenApi\Model\Objects\Objects;
use Tpay\OpenApi\Model\Objects\Recurring\RetryInterval;
use Tpay\OpenApi\Model\Objects\Recurring\Schedule;
use Tpay\OpenApi\Model\Objects\RequestBody\Account;
use Tpay\OpenApi\Model\Objects\RequestBody\Merchant;

Expand Down Expand Up @@ -51,6 +53,15 @@ public function create($fieldName, $parentObject)
}
}

if ($parentObject instanceof Schedule) {
switch ($fieldName) {
case 'retryIntervals':
return new RetryInterval();
default:
throw new InvalidArgumentException(sprintf('Unsupported field "%s" in %s', $fieldName, $parentObject->getName()));
}
}

throw new InvalidArgumentException(sprintf('Field %s as array is not supported in %s object', $fieldName, $parentObject->getName()));
}
}
1 change: 1 addition & 0 deletions src/Manager/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public function setFields($fields, $strictCheck = true)
$this->requestBody->strictCheck = $strictCheck;
$this->requestBody->setObjectValues($this->requestBody, $fields);
$this->ObjectsValidator->isSetRequiredFields($this->requestBody);
$this->ObjectsValidator->validate($this->requestBody);
$this->ObjectsValidator->checkUniqueFields($this->requestBody);

return $this;
Expand Down
14 changes: 14 additions & 0 deletions src/Model/Fields/Notification/Recurring/IterationCount.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace Tpay\OpenApi\Model\Fields\Notification\Recurring;

use Tpay\OpenApi\Model\Fields\Field;

/**
* @method getValue(): string
*/
class IterationCount extends Field
{
protected $name = __CLASS__;
protected $type = self::INT;
}
14 changes: 14 additions & 0 deletions src/Model/Fields/Notification/Recurring/IterationCountAttempt.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace Tpay\OpenApi\Model\Fields\Notification\Recurring;

use Tpay\OpenApi\Model\Fields\Field;

/**
* @method getValue(): string
*/
class IterationCountAttempt extends Field
{
protected $name = __CLASS__;
protected $type = self::INT;
}
14 changes: 14 additions & 0 deletions src/Model/Fields/Notification/Recurring/NextChargeDate.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace Tpay\OpenApi\Model\Fields\Notification\Recurring;

use Tpay\OpenApi\Model\Fields\Field;

/**
* @method getValue(): string
*/
class NextChargeDate extends Field
{
protected $name = __CLASS__;
protected $type = self::STRING;
}
14 changes: 14 additions & 0 deletions src/Model/Fields/Notification/Recurring/Reason.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace Tpay\OpenApi\Model\Fields\Notification\Recurring;

use Tpay\OpenApi\Model\Fields\Field;

/**
* @method getValue(): string
*/
class Reason extends Field
{
protected $name = __CLASS__;
protected $type = self::STRING;
}
14 changes: 14 additions & 0 deletions src/Model/Fields/Notification/Recurring/Status.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace Tpay\OpenApi\Model\Fields\Notification\Recurring;

use Tpay\OpenApi\Model\Fields\Field;

/**
* @method getValue(): string
*/
class Status extends Field
{
protected $name = __CLASS__;
protected $type = self::STRING;
}
14 changes: 14 additions & 0 deletions src/Model/Fields/Notification/Recurring/TransactionId.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace Tpay\OpenApi\Model\Fields\Notification\Recurring;

use Tpay\OpenApi\Model\Fields\Field;

/**
* @method getValue(): string
*/
class TransactionId extends Field
{
protected $name = __CLASS__;
protected $type = self::STRING;
}
15 changes: 15 additions & 0 deletions src/Model/Fields/Recurring/CallbackUrl.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace Tpay\OpenApi\Model\Fields\Recurring;

use Tpay\OpenApi\Model\Fields\Field;

/**
* @method getValue(): string
*/
class CallbackUrl extends Field
{
protected $name = __CLASS__;
protected $type = self::STRING;
protected $maxLength = 255;
}
15 changes: 15 additions & 0 deletions src/Model/Fields/Recurring/Description.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace Tpay\OpenApi\Model\Fields\Recurring;

use Tpay\OpenApi\Model\Fields\Field;

/**
* @method getValue(): string
*/
class Description extends Field
{
protected $name = __CLASS__;
protected $type = self::STRING;
protected $maxLength = 128;
}
15 changes: 15 additions & 0 deletions src/Model/Fields/Recurring/HiddenDescription.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace Tpay\OpenApi\Model\Fields\Recurring;

use Tpay\OpenApi\Model\Fields\Field;

/**
* @method getValue(): string
*/
class HiddenDescription extends Field
{
protected $name = __CLASS__;
protected $type = self::STRING;
protected $maxLength = 255;
}
16 changes: 16 additions & 0 deletions src/Model/Fields/Recurring/Id.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace Tpay\OpenApi\Model\Fields\Recurring;

use Tpay\OpenApi\Model\Fields\Field;

/**
* @method getValue(): string
*/
class Id extends Field
{
protected $name = __CLASS__;
protected $type = self::STRING;
protected $maxLength = 26;
protected $minLength = 26;
}
15 changes: 15 additions & 0 deletions src/Model/Fields/Recurring/PaymentInstrument/BlikModel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace Tpay\OpenApi\Model\Fields\Recurring\PaymentInstrument;

use Tpay\OpenApi\Model\Fields\Field;

/**
* @method getValue(): string
*/
class BlikModel extends Field
{
protected $name = __CLASS__;
protected $type = self::STRING;
protected $enum = ['A', 'M', 'O'];
}
Loading
Loading