pkoznar/comgate-bundle

安装: 7

依赖者: 0

推荐者: 0

安全: 0

星标: 0

关注者: 0

分支: 4

类型:symfony-bundle

dev-master 2022-12-06 08:25 UTC

This package is not auto-updated.

Last update: 2024-09-20 16:46:28 UTC


README

Comgate支付用的symfony扩展包

安装

步骤 1: 使用composer下载MufinComgateBundle

使用composer Composer 需要 mufin/comgate-bundle

$ composer require mufin/comgate-bundle

步骤 2: 启用扩展包

在kernel中启用扩展包

<?php

// app/AppKernel.php
public function registerBundles()
{
    $bundles = array(
        // ...
        new Mufin\ComgateBundle\MufinComgateBundle(),
        // ...
    );
}

步骤 3: 配置MufinComgateBundle

以下是在您的应用程序中使用MufinComgateBundle所需的配置的最小示例

# .env

###> mufin/comgate-bundle ###
MERCHANT_ID="your merchant id"
SECRET_KEY="secret key from comgate dashboard"
TEST_MODE=false
###< mufin/comgate-bundle ###

步骤 4: 使用MufinComgateBundle

# CartController

/**
     * @Route("/cart/payment", name="cart_payment")
     * @param ComgateConnector $comgate
     * @param Request
     * @return Response
     */
    public function payment(ComgateConnector $comgate): Response
    {
        
        $payment = new CreatePayment('PRICE', 'Your order ID', $this->getUser()->getEmail(), 'Some product');
        // to create payment on background according to API requirements
        $payment->setPrepareOnly(true);
        $response = $comgate->send($payment);
        if($response->getMessage()=="OK"){
            // do something with cart
            return $this->redirect($response->getRedirectUrl());
        }

        return $this->render('cart/payment.html.twig', []);
    }