2017 © Pedro Peláez
 

yii2-extension yii2-platron

Yii2 Platron payment gateway API

image

matperez/yii2-platron

Yii2 Platron payment gateway API

  • Friday, October 28, 2016
  • by matperez
  • Repository
  • 1 Watchers
  • 0 Stars
  • 184 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 7 Versions
  • 2 % Grown

The README.md

yii2-platron

Platron.ru payment system merchant API, (*1)

Installation

The preferred way to install this extension is through composer., (*2)

Either run, (*3)

php composer.phar require --prefer-dist matperez/yii2-platron"

or add, (*4)

"matperez/yii2-platron": "~0.0.1"

to the require section of your composer.json file., (*5)

Usage

Config

/** @var \matperez\yii2platron\Platron $platron */
$platron = Yii::createObject([
    'class' => \matperez\yii2platron\Platron::class,
    'secretKey' => 1234,
    'merchantId' => 12345,
    'successUrl' => ['platron/success'],
    'failureUrl' => ['platron/failure'],
]);

It is also could be done through the components config section., (*6)

Init payment

$response = $platron->initPayment(new \matperez\yii2platron\requests\InitPaymentRequest([
    'amount' => 1000,
    'orderId' => 1234,
    'description' => 'amazing goods',
    'params' => [
        'custom_param' => 5
    ],
]));
$paymentIsInitiated = $response->isSuccess();
$redirectUrl = $response->getRedirectUrl();

Revoke payment

$response = $platron->revoke(new \matperez\yii2platron\requests\RevokeRequest([
    'refundAmount' => 1000,
    'paymentId' => 1234,
]));
$transactionIsRevoked = $response->isSuccess();

Check payment status

$response = $platron->getStatus(new \matperez\yii2platron\requests\StatusRequest([
    'payment_id' => 1234,
]));
$responseIsSuccess = $response->isSuccess();
$transactionIsComplete = $response->hasStatus(\matperez\yii2platron\Api::TRANSACTION_STATUS_OK);

Processing the gateway callbacks

Gateway callback processing action might look like this:, (*7)

    /**
     * @return array
     * @throws BadRequestHttpException
     * @throws ServerErrorHttpException
     */
    public function actionResult()
    {
        $request = new ResultRequest(\Yii::$app->request->post());
        if (!$request->validate()) {
            throw new BadRequestHttpException('Invalid result request: '.var_export($request->errors, true));
        }
        $transaction = \Yii::$app->db->beginTransaction();
        $response = new ResultResponse([
            'status' => ResultResponse::STATUS_OK
        ]);
        try {
            // do something to commit or reject the payment..
            $transaction->commit();
        } catch (\Exception $e) {
            $transaction->rollBack();
            $response->status = ResultResponse::STATUS_ERROR;
            $response->errorDescription = $e->getMessage();
        }
        try {
            $data = $this->platron->prepareParams($_SERVER['REQUEST_URI'], $response->getResponseAttributes());
        } catch (\Exception $e) {
            throw new ServerErrorHttpException('Unable to prepare the response: '.$e->getMessage(), $e->getCode(), $e);
        }
        \Yii::$app->response->format = Response::FORMAT_XML;
        return $data;
    }

The Versions

28/10 2016

dev-master

9999999-dev

Yii2 Platron payment gateway API

  Sources   Download

MIT

The Requires

 

The Development Requires

payment gateway yii2 billing

28/10 2016

0.3.0

0.3.0.0

Yii2 Platron payment gateway API

  Sources   Download

MIT

The Requires

 

The Development Requires

payment gateway yii2 billing

15/10 2016

0.2.0

0.2.0.0

Yii2 Platron payment gateway API

  Sources   Download

MIT

The Requires

 

The Development Requires

payment gateway yii2 billing

07/10 2016

0.1.0

0.1.0.0

Yii2 Platron payment gateway API

  Sources   Download

MIT

The Requires

 

The Development Requires

payment gateway yii2 billing

07/10 2016

0.0.3

0.0.3.0

Yii2 Platron payment gateway API

  Sources   Download

MIT

The Requires

 

The Development Requires

payment gateway yii2 billing

07/10 2016

0.0.2

0.0.2.0

Yii2 Platron payment gateway API

  Sources   Download

MIT

The Requires

 

The Development Requires

payment gateway yii2 billing

07/10 2016

0.0.1

0.0.1.0

Yii2 Platron payment gateway API

  Sources   Download

MIT

The Requires

 

The Development Requires

payment gateway yii2 billing