GithubHelp home page GithubHelp logo

alipaybundle's Introduction

GrimmlinkAlipayBundle

SensioLabsInsight

A Symfony Bundle to help you create & submit payment using Alipay's Cross-border Website Payment system (http://global.alipay.com/product/websitepayment.htm)

Requirements

  • cURL
  • openssl

Installation

Installation with composer :

    ...
    "require": {
        ...
        "grimmlink/alipay-bundle": "dev-master",
        ...
    },
    ...

Add this bundle to your app/AppKernel.php :

public function registerBundles()
{
    return array(
        // ...
        new Grimmlink\AlipayBundle\GrimmlinkAlipayBundle(),
        // ...
    );
}

Configuration

Your personnal account informations must be set in your config.yml

# Grimmlink Alipay Bundle
grimmlink_alipay:
    config:
        https_verify_url:   https://mapi.alipay.net/gateway.do          # The API endpoint
        key:                'abcdefghijklmnopqrstuvwxyz123456'          # Your account key - alipay testing environment: 760bdzec6y9goq7ctyx96ezkz78287de
    parameters:
        partner:            '1234567890123456'                          # Your partner number - alipay testing environment: 2088101122136241
        currency:           EUR                                         # Cannot be CNY / RMB !!
        input_charset:      utf-8                                       # 
        service:            create_forex_trade                          # 

Routing

# Grimmlink Alipay Bundle
grimmlink_alipay:
    resource: '@GrimmlinkAlipayBundle/Resources/config/routing.yml'

Usage

In your Payment controller :

...
    $apr = $this->get('grimmlink_alipay.request_handler');
    $apr->setParameters(array(
        'notify_url'        => $this->generateUrl('grimmlink_alipay_notify', array(), true),
        'return_url'        => $this->generateUrl('payment_alipay_return', array(), true), // make it your own
        'out_trade_no'      => $ref,  // make it your own
        'total_fee'         => '0.01', // make it your own
        'subject'           => 'Payment title', // make it your own
        'body'              => 'This is the payment description', // make it your own
    ));
    
    return $this->render('PaymentBundle:Alipay:pay.html.twig', array(
        'url'       => $apr->getUrl(),
        'form'      => $apr->getForm()->createView(),
    ));
...

Do not forget to create the controller action for your return URL, and do not include payment treatment inside, this is done in the Notification event listener.

Then, create your own Alipay Notification service listener, like this :

services:
    ...
    alipay.notification:
        class: Grimmlink\PaymentBundle\EventListener\AlipayListener
        tags:
            - { name: kernel.event_listener, event: alipay.notify_response, method: onAlipayNotificationResponse }

Create your Listener class and put your payment logic inside The AlipayResponseEvent contains

  • data : the Query parameters sent by Alipay
  • response : "true" if the notification has been validated
  • signed : boolean - is the Alipay response's signature valid

alipaybundle's People

Contributors

grimmlink avatar

Stargazers

Xun Zhou avatar lcpeng avatar

Watchers

 avatar  avatar

Forkers

komet merabchik

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.