bawes/myfatoorah-php 问题修复 & 功能扩展

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

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

bawes/myfatoorah-php

Composer 安装命令:

composer require bawes/myfatoorah-php

包简介

MyFatoorah PHP Library

README 文档

README

Latest Version Software License Total Downloads

Installation

The preferred way to install this library is through composer.

Either run

$ composer require bawes/myfatoorah-php

or add

"bawes/myfatoorah-php": "^1.0"

to the require section of your application's composer.json file.

Usage

First we need to decide which environment we want to use

Step 1: Initialize based on the environment

Test Environment

<?php
use bawes/myfatoorah/MyFatoorah;

$my = MyFatoorah::test();

Live Environment

<?php
use bawes/myfatoorah/MyFatoorah;

$merchantCode = "[Your merchant code here]";
$username = "[Your merchant username here]";
$password = "[Your merchant password here]";
$my = MyFatoorah::live($merchantCode, $username, $password);

Step 2: Request a payment link and redirect to it

<?php
use bawes/myfatoorah/MyFatoorah;

$merchantCode = "[Your merchant code here]";
$username = "[Your merchant username here]";
$password = "[Your merchant password here]";
$my = MyFatoorah::live($merchantCode, $username, $password);

$my->setPaymentMode(MyFatoorah::GATEWAY_ALL)
->setReturnUrl("https://google.com")
->setErrorReturnUrl("https://google.com")
->setCustomer("Khalid", "customer@email.com", "97738271")
->setReferenceId() //Pass unique order number or leave empty to use time()
->addProduct("iPhone", 5.350, 3)
->addProduct("Samsung", 12.000, 1)
->getPaymentLinkAndReference();

$paymentUrl = $my['paymentUrl'];
$myfatoorahRefId = $my['paymentRef']; //good idea to store this for later status checks

// Redirect to payment url
header("Location: $paymentUrl");
die();

Step 3: Request Order Status for Payment status confirmation

Use MyFatoorah::getOrderStatus($referenceId) to get an update on the status of the payment. This is best called after receiving a callback from MyFatoorah's returnUrl or errorReturnUrl. You can also manually call this function after an interval if you store the reference id locally.

Sample Order Status Request

<?php
use bawes/myfatoorah/MyFatoorah;

// Example Ref ID
$myfatoorahRefId = $_GET['id'];

// Order status on Test environment
$orderStatus = MyFatoorah::test()
    ->getOrderStatus($myfatoorahRefId);

// Order status on Live environment
$merchantCode = "[Your merchant code here]";
$username = "[Your merchant username here]";
$password = "[Your merchant password here]";
$orderStatus = MyFatoorah::live($merchantCode, $username, $password)
    ->getOrderStatus($myfatoorahRefId);

Order Status Response (Success)

<?php
$orderStatus = [
    'responseCode' => '0', //MyFatoorah::REQUEST_SUCCESSFUL
    'responseMessage' => 'SUCCESS',
    'result' => 'CAPTURED',

    // Successful payment fields
    'payMode' => 'KNET',
    'orderId' => '1085183',
    'payTransactionId' => '673386261283050',
    'grossAmountPaid' => '32.500',
    'netAmountToBeDeposited' => '32.300',

    // User defined fields
    'udf1' => '',
    'udf2' => '',
    'udf3' => '',
    'udf4' => '',
    'udf5' => ''
]

Order Status Response (Failure)

<?php
$orderStatus = [
    'responseCode' => '2009',
    'responseMessage' => 'Transaction Failed Messages',
    'result' => 'Payment Server detected an error',

    // User defined fields
    'udf1' => '',
    'udf2' => '',
    'udf3' => '',
    'udf4' => '',
    'udf5' => ''
]

Payment Gateways

Configure the gateway you wish to use by passing GATEWAY constants available on the MyFatoorah class to MyFatoorah::setPaymentMode.

  • MyFatoorah::GATEWAY_ALL - Generated link sends to MyFatoorah page with all payment methods
  • MyFatoorah::GATEWAY_KNET - Generated link sends user directly to KNET portal
  • MyFatoorah::GATEWAY_VISA_MASTERCARD - Generated link sends user directly to VISA/MASTER portal
  • MyFatoorah::GATEWAY_SAUDI_SADAD - Generated link sends user directly to Sadad Saudi portal
  • MyFatoorah::GATEWAY_BAHRAIN_BENEFIT - Generated link sends user directly to BENEFIT BAHRAIN portal
  • MyFatoorah::GATEWAY_QATAR_QPAY - Generated link sends user directly to Qpay Qatar portal
  • MyFatoorah::GATEWAY_UAECC - Generated link sends user directly to UAE debit cards portal

Usage Example:

<?php
use bawes/myfatoorah/MyFatoorah;

$my = MyFatoorah::live($merchantCode, $username, $password);
$my->setPaymentMode(MyFatoorah::GATEWAY_ALL)

Test cards

These cards will only work if you initialize using MyFatoorah::test() environment.

KNET

Card Number Pin/Expiry Result
8888880000000001 anything CAPTURED
8888880000000002 anything NOT CAPTURED

Benefits

Card Number Expiry Date Pin Result
2222220123456789 12/27 1234 CAPTURED
7777770123456789 12/27 1234 NOT CAPTURED
1111110123456789 12/27 1234 NOT CAPTURED

Visa

Card Number Expiry Date CVV
4005550000000001 05/18 123
4557012345678902 05/18 123

Mastercard

Card Number Expiry Date CVV
5123456789012346 05/18 123
5313581000123430 05/18 123

Amex

Card Number Expiry Date Pin
345678901234564 05/17 1234

Sadad

Payment Method Card Number Expiry Date CVV
Mastercard 5271045423029111 anything anything
Visa 4012001037141112 01/2022 684
Payment Method Account ID Password
Sadad account arun123 Aa123456

bawes/myfatoorah-php 适用场景与选型建议

bawes/myfatoorah-php 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 969 次下载、GitHub Stars 达 5, 最近一次更新时间为 2018 年 10 月 27 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「api」 「payment processing」 「myfatoorah」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 bawes/myfatoorah-php 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 bawes/myfatoorah-php 我们能提供哪些服务?
定制开发 / 二次开发

基于 bawes/myfatoorah-php 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

  • Stars: 5
  • Watchers: 1
  • Forks: 4
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-10-27