chargily/epay-symfony

此包已被弃用且不再维护。作者建议使用chargily/epay-symfony包。

Chargily ePay 插件用于 symfony。

安装: 0

依赖项: 0

建议者: 0

安全性: 0

星标: 2

观察者: 1

分支: 1

开放问题: 0

类型:symfony-bundle

This package is auto-updated.

Last update: 2024-02-09 13:35:03 UTC


README

Chargily ePay 通道的 symfony 插件

Chargily ePay Gateway

安装

  1. 通过 Composer(推荐)
composer require chargily/epay-symfony
  1. 注册包,在 config/bundles.php 文件末尾添加以下行
\Chargily\SymfonyBundle\ChargilySymfonyBundle::class => ['all' => true],
  1. 导入服务,在 config/services.yml 中添加以下行
imports:
    - { resource: "@ChargilySymfonyBundle/config/services.yaml" }
  1. 配置 API 密钥,在 config/services.yml 中添加以下行
parameters:
    api_key: "API_KEY"
    secret_key: "SECRET_KEY"
  1. 处理支付并将重定向到支付页面
        $payload = array(
            "client" => "test",
            'client_email' => "test@gmail.com",
            "invoice_number" => '123456789',
            "amount" => 110,
            'discount' => 0,
            'mode' => 'CIB',
            'back_url' => "https://test.com",
            'webhook_url' => "https://test.com" . "/" . "webHookSuffixRoute". "/" ."OrderNumber",
            //back_url example when you want to take your host base url
            //'back_url'  => $request->getSchemeAndHttpHost(),
            //webhook_url example when you want to take your host base url and add your suffix route for the webhook
            //'webhook_url' => $request->getSchemeAndHttpHost() . "/" . you_back_url_suffix_here . "/" .Order_Number,
            'comment' => 'My Payment Comment.',
            'api_key' => $this->getParameter('api_key'),
        );

        $chargyliController = new ChargilyEpaySymfonyController();

        $response = $chargyliController->pay($payload);
        $status_code = $response->getStatusCode();
        $response = json_decode($response->getContent());
        if ($status_code == 200) {
            //redirect to chargily payment gateway
            return $this->redirect($response->response);
        } else {
            // This is a error message depending on issue that happen
            dd($status_code . " " . $response->response);
        }
  1. 处理支付的成功消息
200 => getting redirection link with success => Redirection to url
  1. 处理支付的错误消息
400 => There mode must be CIB,EDAHABIA option Only
400 => There amount must be numeric and greather or equal than 75
400 => There is issue \for connecting payment gateway. Sorry \for the inconvenience => with error message
400 => There is missing information in payment parameters
  1. Webhook 模板
    /**
     * @Route("/chargily/webhook/{OrderNumber}",name="chargily_webhook")
     * @throws \Exception
     */
    public function chargilyWebhook(Request $request)
    {
        //getting your order number
        $number = $request->attributes->get('OrderNumber');

        //part or code for searching your order by number
        /*
         *
         */

        //getting request content
        $data = json_decode($request->getContent(), true);
        $headers = json_decode($request->headers, true);

        $hashedData =  hash_hmac('sha256', json_encode($data) , $this->getParameter('secret_key'));

        if (isset($data) and isset($number)) {
            if($data['invoice']['status'] == 'paid'){

                //part where you update your order status for paid status

                return new JsonResponse([
                    'code' => 200,
                    'message' => 'Update status with success'
                ]);
            }elseif($data['invoice']['status'] == 'failed'){
                //part where you update your order status for failed status

                return new JsonResponse([
                    'code' => 200,
                    'message' => 'Update status with success'
                ]);
            }
            elseif( $data['invoice']['status'] == 'canceled'){
                //part where you update your order status for canceled status
                return new JsonResponse([
                    'code' => 200,
                    'message' => 'Update status with success'
                ]);
            }
        } else {
            return new JsonResponse([
                'code' => 400,
                'message' => 'Update status Failed'
            ]);
        }

    }
  1. 清除缓存并享受
php bin/console cache:clear

此插件旨在轻松集成 ePayment 通道与 Chargily。

  • 目前支持通过 CIB / EDAHABIA 卡支付,并很快将支持 Visa / Mastercard
  • 此仓库最近创建用于 Sylius 插件,如果您是开发者并希望为此插件的开发做出贡献,欢迎加入!

贡献提示

  1. 将此仓库进行分支。
  2. 浏览我们此处的 API 文档。
  3. Chargily ePay仪表板免费获取您的 API 密钥/密钥。
  4. 开始开发。
  5. 完成?推送并合并。