承接 matperez/yii2-platron 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

matperez/yii2-platron

Composer 安装命令:

composer require matperez/yii2-platron

包简介

Yii2 Platron payment gateway API

README 文档

README

Platron.ru payment system merchant API

Installation

The preferred way to install this extension is through composer.

Either run

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

or add

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

to the require section of your composer.json file.

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.

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:

    /**
     * @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;
    }

统计信息

  • 总下载量: 7.93k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-10-07

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固