sillsoft / yii2-liqpay
https://www.liqpay.ua/ checkout
dev-master
2023-07-09 19:25 UTC
Requires
- yiisoft/yii2: ~2.0.0
This package is auto-updated.
Last update: 2024-09-09 21:46:27 UTC
README
安装
安装此扩展的首选方法是通过 composer。
可以运行
php composer.phar require --prefer-dist sillsoft/yii2-liqpay "*"
或者添加
"sillsoft/yii2-liqpay": "*"
到你的 composer.json
文件的 require 部分中。
使用
config.php
'modules' => [ 'liqpay' => [ 'class' => 'sillsoft\liqpay\Module', 'publicKey' => '', 'privateKey' => '', ], ]
控制器
$order_id = 1; $repository = Yii::$container->get(LiqPayPaymentRepository::class); $orderModel = $repository->createOrUpdate($order_id); $liqpay = Yii::$container->get(Liqpay::class); return $liqpay->renderPaymentForm([ 'amount' => 10, 'currency' => 'UAH', 'description' => Yii::t('frontend', 'Оплата за товари'), 'order_id' => $order_id, 'language' => Yii::$app->language, 'result_url' => Yii::$app->urlManager->createAbsoluteUrl(['/checkout/thanks']), 'server_url' => Yii::$app->urlManager->createAbsoluteUrl(['/liq-pay/server']), ]);
回调
public function actionServer(): Response { $request = Yii::$app->getRequest(); if ($request->getIsPost()) { $data = $request->post('data'); $orderId = ArrayHelper::getValue($data, 'order_id', false); $data = json_decode(base64_decode($data), true); $repository = Yii::$container->get(LiqPayPaymentRepository::class); $orderModel = $repository->findOneByOrderId($orderId); if (!$orderModel) throw new ErrorException("Payment By Order Id $orderId not found"); $repository = Yii::$container->get(LiqPayPaymentRepository::class); $repository->createOrUpdate($orderId, $data); return $this->asJson([ 'success' => true ]); } throw new BadRequestHttpException(); }