PHPackages                             mantoufan/alipay-global-sdk-php - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Payment Processing](/categories/payments)
4. /
5. mantoufan/alipay-global-sdk-php

ActiveLibrary[Payment Processing](/categories/payments)

mantoufan/alipay-global-sdk-php
===============================

Alipay Global Third Party SDK

0.0.3(3y ago)3971.2k69[1 issues](https://github.com/mantoufan/alipay-global-sdk-php/issues)MPL-2.0PHP

Since Feb 7Pushed 3y ago3 watchersCompare

[ Source](https://github.com/mantoufan/alipay-global-sdk-php)[ Packagist](https://packagist.org/packages/mantoufan/alipay-global-sdk-php)[ RSS](/packages/mantoufan-alipay-global-sdk-php/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (4)Used By (0)

Alipay Global SDK PHP
=====================

[](#alipay-global-sdk-php)

Alipay Global A+ SDK
--------------------

[](#alipay-global-a-sdk)

This project is based on [Alipay Global Offical PHP SDK](https://github.com/alipay/global-open-sdk-php)
Since official SDK mainly shows how to access the alipay gateway and does not contain complete functions such as authorization and auto debit, I have added some logic and further realized the standard interface of Alipay Global A+

Attention!
----------

[](#attention)

0.0.3+: `sendNotifyResponse` `sendNotifyResponseWithRSA` are methods of `$notify`, eg:

```
$notify = $alipayGlobal->getNotify();
$notify->sendNotifyResponse(); // $alipayGlobal->sendNotifyResponse() is desprecated
$notify->sendNotifyResponseWithRSA(); // $alipayGlobal->sendNotifyResponseWithRSA() is desprecated
/* getNotifyResponse and getNotifyResponseWithRSA are added,
   so you can process it by yourself in memory frameworks like Webman */
$notifyResponseWithRSA =  $notify->getNotifyResponse();
$notifyResponseWithRSA =  $notify->getNotifyResponseWithRSA();
```

Demo
----

[](#demo)

The use and functionality of the SDK have been shown with **Examples** in the project folder

Use
---

[](#use)

```
composer require mantoufan/alipay-global-sdk-php
```

How to use
----------

[](#how-to-use)

### Initialize

[](#initialize)

```
$alipayGlobal = new Mantoufan\AliPayGlobal(array(
    'client_id' => 'SANDBOX_5Y3A2N2YEB3002022', // Client ID
    'endpoint_area' => 'ASIA', // Optional: NORTH_AMERIA / ASIA / EUROPE
    'merchantPrivateKey' => '', // Merchant Private Key
    'alipayPublicKey' => '', // Alipay Public Key
    'is_sandbox' => true, // Whether to use the Sandbox environment
));
```

Required fields will be mark with `*`

### Online payment - Payment - Pay (Cashier Payment)

[](#online-payment---payment---pay-cashier-payment)

API: [ac/ams/payment\_cashier](https://global.alipay.com/docs/ac/ams/payment_cashier)
DEMO: [pay/cashier](https://p.yzhan.co/alipay-global-sdk-php/example/?type=pay/cashier)

```
use Mantoufan\model\CustomerBelongsTo;
use Mantoufan\model\TerminalType;
try {
  $result = $alipayGlobal->payCashier(array(
      'customer_belongs_to' => CustomerBelongsTo::ALIPAY_CN, // * Users pay with Alipay Chinese wallet，Optional: ALIPAY_CN / ALIPAY_HK / TRUEMONEY / TNG / GCASH / DANA / KAKAOPAY / EASYPAISA / BKASH
      'notify_url' => '', // Asynchronous callback Url
      'return_url' => '', // Synchronize callback Url
      'amount' => array(
          'currency' => 'USD', // Currency of payment
          'value' => '1', // Amount of payment
      ),
      'order' => array(
          'id' => null, // Order No
          'desc' => 'Order Desc', // Order Description
          'extend_info' => array(
              'china_extra_trans_info' => array(
                  'business_type' => 'MEMBERSHIP', // Business Type of Order
              ),
          ),
      ),
      'payment_request_id' => null, // Cash payments could be null
      'settlement_strategy' => array(
          'currency' => 'USD', // Currency used for settlement
      ),
      'terminal_type' => TerminalType::WEB, // * Optional: WEB / WAP / APP
      'os_type' => null, // OS System Type
  ));
  header('Location: ' . $result->normalUrl); // Return URL of the alipay cashier
} catch (Exception $e) {
  echo $e->getMessage(); // Output Error
}
```

### Online Payment - Authorization - Consult

[](#online-payment---authorization---consult)

API: [ac/ams/authconsult](https://global.alipay.com/docs/ac/ams/authconsult)
DEMO: [auth/consult](https://p.yzhan.co/alipay-global-sdk-php/example/?type=auth/consult)

```
use Mantoufan\tool\IdTool;
use Mantoufan\model\ScopeType;
use Mantoufan\model\TerminalType;
$auth_state = IdTool::CreateAuthState();
try {
    $result = $alipayGlobal->authConsult(array(
        'customer_belongs_to' => CustomerBelongsTo::ALIPAY_CN, // * Users pay with Alipay Chinese wallet，Optional: ALIPAY_CN / ALIPAY_HK / TRUEMONEY / TNG / GCASH / DANA / KAKAOPAY / EASYPAISA / BKASH
        'auth_client_id' => null, // Unique ID of the secondary merchant
        'auth_redirect_url' => '', // * URL that User is redirected to after User agrees to authorize
        'scopes' => array(ScopeType::AGREEMENT_PAY), // * Optional AGREEMENT_PAY / BASE_USER_INFO / USER_INFO / USER_LOGIN_ID / HASH_LOGIN_ID / SEND_OTP
        'auth_state' => $auth_state, // * It will be returned when User agrees to authorize needs to be guaranteed
        'terminal_type' => TerminalType::WEB, // * Optional: WEB / WAP / APP
        'os_type' => null, // OS System Type
    ));
    header('Location: ' . $result->normalUrl); // Return URL of User Authorization page With authCode
} catch (Exception $e) {
    echo $e->getMessage(); // Output Error
}
```

### Online Payment - Authorization - ApplyToken - Using AuthCode

[](#online-payment---authorization---applytoken---using-authcode)

API: [ac/ams/accesstokenapp](https://global.alipay.com/docs/ac/ams/accesstokenapp)
DEMO: [auth/apply\_token/auth\_code](https://p.yzhan.co/alipay-global-sdk-php/example/?type=auth/apply_token/auth_code)

```
use Mantoufan\model\CustomerBelongsTo;
use Mantoufan\model\GrantType;
$auth_code = $_GET['authCode'] ?? '';
try {
    $result = $alipayGlobal->authApplyToken(array(
        'grant_type' => GrantType::AUTHORIZATION_CODE, // * Value should be AUTHORIZATION_CODE
        'customer_belongs_to' => CustomerBelongsTo::ALIPAY_CN, // * Users pay with Alipay Chinese wallet，Optional: ALIPAY_CN / ALIPAY_HK / TRUEMONEY / TNG / GCASH / DANA / KAKAOPAY / EASYPAISA / BKASH
        'auth_code' => $auth_code, // * AuthCode get from return URL of User Authorization page
        'refresh_token' => null, // Just leave null
    ));

    $access_token = $result->accessToken; // Access token is used for Aduto Debit
    $access_token_expiry_time = $result->accessTokenExpiryTime; // Access token expiry time
    $refresh_token = $result->refreshToken; // Refresh token is used for update access token
    $refresh_token_expiry_time = $result->refreshTokenExpiryTime; // Refresh token expiry time
    session_start(); // Start Session
    $_SESSION['access_token'] = $access_token; // Store Accesstoken in session
} catch (Exception $e) {
    echo $e->getMessage(); // Output Error
}
```

### Online Payment - Authorization - ApplyToken - Using RefreshToken

[](#online-payment---authorization---applytoken---using-refreshtoken)

API: [ac/ams/accesstokenapp](https://global.alipay.com/docs/ac/ams/accesstokenapp)
DEMO: [auth/apply\_token/refresh\_token](https://p.yzhan.co/alipay-global-sdk-php/example/?type=auth/apply_token/refresh_token)

```
use Mantoufan\model\CustomerBelongsTo;
use Mantoufan\model\GrantType;
$refresh_token = $_GET['refreshToken'] ?? '';
try {
    $result = $alipayGlobal->authApplyToken(array(
        'grant_type' => GrantType::REFRESH_TOKEN, // * Value should be REFRESH_TOKEN
        'customer_belongs_to' => CustomerBelongsTo::ALIPAY_CN, // * Users pay with Alipay Chinese wallet，Optional: ALIPAY_CN / ALIPAY_HK / TRUEMONEY / TNG / GCASH / DANA / KAKAOPAY / EASYPAISA / BKASH
        'auth_code' => null, // Just leave null
        'refresh_token' => $refresh_token, // * RefreshToken get from authApplyToken Using AuthCode
    ));

    $access_token = $result->accessToken; // Access token is used for Aduto Debit
    $access_token_expiry_time = $result->accessTokenExpiryTime; // Access token expiry time
    $refresh_token = $result->refreshToken; // Refresh token is used for update access token
    $refresh_token_expiry_time = $result->refreshTokenExpiryTime; // Refresh token expiry time
    session_start(); // Start Session
    $_SESSION['access_token'] = $result->accessToken; // Store Accesstoken in session
} catch (Exception $e) {
    echo $e->getMessage(); // Output Error
}
```

### Online payment - Payment - Pay (Auto Debit)

[](#online-payment---payment---pay-auto-debit)

API: [ac/ams/payment\_agreement](https://global.alipay.com/docs/ac/ams/payment_agreement)
DEMO: [pay/agreement](https://p.yzhan.co/alipay-global-sdk-php/example/?type=pay/agreement)

```
try {
    session_start();
    $result = $alipayGlobal->payAgreement(array(
        'notify_url' => '', // Asynchronous callback Url
        'return_url' => '', // Synchronous callback Url
        'amount' => array(
            'currency' => 'USD', // Currency of payment
            'value' => '1', // Amount of payment
        ),
        'order' => array(
            'id' => null, // Order No
            'desc' => 'Order Desc', // Order Description
            'extend_info' => array(
                'china_extra_trans_info' => array(
                    'business_type' => 'MEMBERSHIP', // Business Type of Order
                ),
            ),
        ),
        'goods' => array(
            array(
                'id' => null, // Goods ID
                'name' => 'Goods Name', // Goods Name
                'category' => null, // Goods Category
                'brand' => null, // Goods Brand
                'unit_amount' => null, // Goods Charge Unit
                'quantity' => null, // Goods Quantity
                'sku_name' => null, // Goods SKU Name
            ),
        ),
        'merchant' => array( // Secondary merchant Info
            'MCC' => null,
            'name' => null,
            'display_name' => null,
            'address' => null,
            'register_date' => null,
            'store' => null,
            'type' => null,
        ),
        'buyer' => array( // Buyer Info
            'id' => null, // Buyer ID
            'name' => array(
                'first_name' => 'David', // * Buyer First Name
                'last_name' => 'Chen', // * Buyer Last Name
            ),
            'phone_no' => null, // Buyer Phone Number
            'email' => null, // Buyer Email
        ),
        'payment_request_id' => null, // Auto Debit payments could be null
        'payment_method' => array(
            'payment_method_type' => CustomerBelongsTo::ALIPAY_CN, // * Users pay with Alipay Chinese wallet，Optional: ALIPAY_CN / ALIPAY_HK / TRUEMONEY / TNG / GCASH / DANA / KAKAOPAY / EASYPAISA / BKASH
            'payment_method_id' => $_SESSION['access_token'], // * AccessToken returned by applyToken
        ),
        'settlement_strategy' => array(
            'currency' => 'USD', // Currency used for settlement
        ),
        'terminal_type' => TerminalType::WEB, // * Optional: WEB / WAP / APP
        'os_type' => null, // OS Type
    ));
    var_dump($result); // Output Result
} catch (Exception $e) {
    echo $e->getMessage(); // Output Error
}
```

### Online payment - Payment - NotifyPayment

[](#online-payment---payment---notifypayment)

API: [ac/ams/paymentrn\_online](https://global.alipay.com/docs/ac/ams/paymentrn_online)
DEMO: [notify](https://p.yzhan.co/alipay-global-sdk-php/example/?type=notify)

```
try {
    /* Get Asynchronous Payment Notifications */
    $notify = $alipayGlobal->getNotify();
    /* Default Value same as:
    $notify = $alipayGlobal->getNotify(array(
        'httpMethod' => $_SERVER['REQUEST_METHOD'],
        'path' => $_SERVER['REQUEST_URI'],
        'clientId' => $_SERVER['HTTP_CLIENT_ID'],
        'rsqTime' => $_SERVER['HTTP_REQUEST_TIME'],
        'rsqBody' => file_get_contents('php://input'),
        'signature' => $_SERVER['HTTP_SIGNATURE']
    ));*/
    /* Webman Example:
    $notify = $alipayGlobal->getNotify(array(
        'httpMethod' => $request->method(),
        'path' => $request->uri(),
        'clientId' => $request->header('client-id'),
        'rsqTime' => $request->header('request-time'),
        'rsqBody' => $request->rawBody(),
        'signature' => $request->header('signature')
    ));*/

    // Do something

    // Method 1: use header () and echo response
    $notify->sendNotifyResponseWithRSA(); // Tell Alipay Global the notice has been received and there is no need to send it again

    // Method 2: Or Get headers and body, process it by yourself
    $notifyResponseWithRSA =  $notify->getNotifyResponseWithRSA();
    // Webman Example:
    // response($notifyResponseWithRSA['body'], 200, $notifyResponseWithRSA['headers']);
} catch (Exception $e) {
    echo $e->getMessage(); // Output Error
}
```

### Online Payment - Authorization - NotifyAuthorization

[](#online-payment---authorization---notifyauthorization)

API: [ac/ams/notifyauth](https://global.alipay.com/docs/ac/ams/notifyauth)
DEMO: [notify/auth/auth\_code](https://p.yzhan.co/alipay-global-sdk-php/example/?type=notify/auth/auth_code)

```
try {
    /* Get Asynchronous Payment Notifications */
    $notify = $alipayGlobal->getNotify();
    /* Default Value same as:
    $notify = $alipayGlobal->getNotify(array(
        'httpMethod' => $_SERVER['REQUEST_METHOD'],
        'path' => $_SERVER['REQUEST_URI'],
        'clientId' => $_SERVER['HTTP_CLIENT_ID'],
        'rsqTime' => $_SERVER['HTTP_REQUEST_TIME'],
        'rsqBody' => file_get_contents('php://input'),
        'signature' => $_SERVER['HTTP_SIGNATURE']
    ));*/
    /* Webman Example:
    $notify = $alipayGlobal->getNotify(array(
        'httpMethod' => $request->method(),
        'path' => $request->uri(),
        'clientId' => $request->header('client-id'),
        'rsqTime' => $request->header('request-time'),
        'rsqBody' => $request->rawBody(),
        'signature' => $request->header('signature')
    ));*/

    // Do something

    $rsqBody = $notify->getRsqBody(); // Get Response Body of Notification
    $authorization_notify_type = $reqBody->authorizationNotifyType; // Determine Notification Type
    if ($authorization_notify_type === 'AUTHCODE_CREATED') { // If Notification Type is sent AuthCode
        $_SESSION['auth_code'] = $reqBody->authCode; // Get AuthCode
    }

    // Method 1: use header () and echo response
    $notify->sendNotifyResponseWithRSA(); // Tell Alipay Global the notice has been received and there is no need to send it again

    // Method 2: Or Get headers and body, process it by yourself
    $notifyResponseWithRSA =  $notify->getNotifyResponseWithRSA();
    // Webman Example:
    // response($notifyResponseWithRSA['body'], 200, $notifyResponseWithRSA['headers']);
} catch (Exception $e) {
    echo $e->getMessage(); // Output Error
}
```

### Online Payment - Refund - Refund

[](#online-payment---refund---refund)

API: [ac/ams/refund\_online](https://global.alipay.com/docs/ac/ams/refund_online)
DEMO: [refund/refund\_online](https://p.yzhan.co/alipay-global-sdk-php/example/?type=refund/refund_online)

```
try {
    $result = $alipayGlobal->sendRefund(array(
        'paymentId' => '20181129190741010007000000XXXX', // Unique ID assigned by Alipay for the original payment to be refunded.
        'refundRequestId' => 'S7mMoYxQxWjJDWwm2NG4WxmNbM5z3GvSB6PEPvMeYP21PQUtrX9hXlgbQMajt2on', // Unique ID assigned by the merchant to identify a refund request.
        'refundAmount' => array(
            'currency' => 'USD', // Currency of refund
            'value' => '100', // Amount of refund
        )
    ));
    var_dump($result);
} catch (Exception $e) {
    echo $e->getMessage();
}
```

### Return Url

[](#return-url)

DEMO: [return](https://p.yzhan.co/alipay-global-sdk-php/example/?type=return)

```
/** Return immediately after payment or authorization
 * After Payment, user will be redirected only
 * After Authorization, user will be redirected with authCode
 * Suggestion: The Return URL is only used as a reminder
 * It's beter to process business in asynchronous payment notification and asynchronous authorization notification
**/
echo 'Payment Or Authorization completed';
```

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity39

Limited adoption so far

Community17

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 95.2% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~100 days

Total

3

Last Release

1355d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/186219fca45bab5c5266d7c1f22c79c217f21ba7ada3142795a8ae69f95be0f6?d=identicon)[mantoufan](/maintainers/mantoufan)

---

Top Contributors

[![mantoufan](https://avatars.githubusercontent.com/u/4961543?v=4)](https://github.com/mantoufan "mantoufan (20 commits)")[![listill](https://avatars.githubusercontent.com/u/15646491?v=4)](https://github.com/listill "listill (1 commits)")

---

Tags

alipaypaymentsdk

### Embed Badge

![Health badge](/badges/mantoufan-alipay-global-sdk-php/health.svg)

```
[![Health](https://phpackages.com/badges/mantoufan-alipay-global-sdk-php/health.svg)](https://phpackages.com/packages/mantoufan-alipay-global-sdk-php)
```

###  Alternatives

[omnipay/paypal

PayPal gateway for Omnipay payment processing library

3156.8M53](/packages/omnipay-paypal)[eduardokum/laravel-boleto

Biblioteca com boletos para o laravel

626351.9k2](/packages/eduardokum-laravel-boleto)[tbbc/money-bundle

This is a Symfony bundle that integrates moneyphp/money library (Fowler pattern): https://github.com/moneyphp/money.

1961.9M](/packages/tbbc-money-bundle)[2checkout/2checkout-php

2Checkout PHP Library

83740.3k2](/packages/2checkout-2checkout-php)[smhg/sepa-qr-data

Generate QR code data for SEPA payments

61717.2k5](/packages/smhg-sepa-qr-data)[omnipay/dummy

Dummy driver for the Omnipay payment processing library

271.2M33](/packages/omnipay-dummy)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
