gemfourmedia/omnipay-zalopay 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

gemfourmedia/omnipay-zalopay

最新稳定版本:v1.0.0

Composer 安装命令:

composer require gemfourmedia/omnipay-zalopay

包简介

ZaloPay gateway driver for Omnipay.

README 文档

README

ZaloPay gateway for Omnipay League.

Installation

WIP: via Composer:

composer require gemfourmedia/omnipay-zalopay

Usage

Init gateway:

use Omnipay\Omnipay;

$gateway = Omnipay::create('ZaloPay');
$gateway->initialize([
    'app_user' => 'Your App Name',
    'app_id' => 'Provided by ZaloPay',
    'key1' => 'Provided by ZaloPay',
    'key2' => 'Provided by ZaloPay',
    'testMode' => true // 'Enable sandbox mode',
]);

This gateway object will use to handle request/response from ZaloPay

Create Purchase:

$appTime = floor(microtime(true) * 1000);
$appTransId = date('ymd').$this->order->order_number.$appTime;

$response =  $gateway->purchase([
    // Required parameters
    'app_trans_id' => $appTransId,
    'app_time' => $appTime,
    'amount' => $order->amount, //Eg: 1000000
    'description' => 'YOUR APP - Payment for order No. #'.$order->order_number,
    'item' => json_encode([]),
    'embed_data' => json_encode((object)['redirecturl' => 'https://your-domain.com/callback_url']),
    'bank_code' => '', //''|CC|ATM|Domestic bank code detail at https://docs.zalopay.vn/v2/docs/gateway/api.html#mo-ta_dac-ta-api
    'returnUrl'    => 'https://your-domain.com/callback_listener', // This will assign to callback_url is use by ZaloPay
    
    // Optional parameters
    'order_type' => 'GOODS', // can be:GOODS/TRANSPORTATION/HOTEL/FOOD/TELCARD/BILLING
    'title' => 'Order Title',
    'device_info' => json_encode([]),
    'currency' => 'VND',
    'phone' => '0902381299',
    'email' => 'gemfourmedia@gmail.com',
    'address' => '123 Alexandre De Rhodes',
    'sub_app_id' => '',
])->send();

if ($response->isRedirect()) {
    $redirectUrl = $response->getRedirectUrl();
    
    // TODO: redirect to $redirectUrl for customer can make payment via ZaloPay
}

Read more detail here.

Validate ZaloPay redirect:

$response = $gateway->completePurchase()->send();

if ($response->isSuccessful()) {
    // TODO: Handle data.
    $data = $response->getData();
    $appTransId = $data['apptransid'];

    // SUGGESTION: do query transaction to make sure transaction is successful:
    // $gateway()->queryTransaction(['app_trans_id' => $appTransId])->send()
    
} else {

    print $response->getMessage();
}

Read more detail here.

Check callback (IPN) from ZaloPay

$response = $gateway->notification()->send();

if ($response->isSuccessful()) {
	// TODO: Handle data.
	$data = $response->getData();
} else {
	print $response->getMessage();
}

Read more detail here.

Query transaction:

$gateway()->queryTransaction(['app_trans_id' => $appTransId])->send()

if ($response->isSuccessful()) {
    // TODO: handle data.
    $data = $response->getData()
    
} else {
    print $response->getMessage();
}

Read more detail here.

Refund:

WIP

Query Refund:

WIP

Debug:

Some general methods use when isSuccessful() return FALSE:

    print $response->getCode(); // Error Code From ZaloPay.
    print $response->getMessage(); // Error Message From ZaloPay.

Detail status errors for getCode() read here.

统计信息

  • 总下载量: 15
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-02-05

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固