chipdeals / momo-api
简单易用的移动货币API,可访问非洲所有移动钱包
Requires
- guzzlehttp/guzzle: ^6.5 || ^7.0
README
其他库文档
Chipdeals-momo-api 是一个移动货币API,它允许你在网站和原生应用中快速、简单、高质量地构建支付体验。这是官方 Php laravel库
要求
Laravel 8 或更高版本
安装
composer require chipdeals/momo-api
快速开始
使用你的API密钥(在此获取apikey)初始化Chipdeals Momo API并开始使用
$momo = new \Chipdeals\MomoApi\Momo();
$momo->setApiKey("test_FOdigzgSopV8GZggZa89");
//Collect 500 XOF from the +22951010200 Mobile Money wallet.
$collection = $momo
->collect()
->amount(500)
->currency("XOF")
->from('22951010200')
->create();
print_r($collection->getArray());
//Send 2000 XOF to the +22951010200 Mobile Money wallet.
$deposit = $momo
->deposit()
->amount(2000)
->currency("XOF")
->to('22951010200')
->create();
print_r($deposit->getArray());
使用 沙箱测试 快速检查可能的响应
使用方法
该包需要配置你的 账户的API密钥,在获取Chipdeals沙箱访问权限时可用。
收集货币
简单收集
例如,要从 +22951010200 移动货币钱包请求2000 XOF,可以使用以下代码
$momo = new \Chipdeals\MomoApi\Momo();
$momo->setApiKey("test_FOdigzgSopV8GZggZa89");
$collection = $momo
->collect()
->amount(2000) //Amount of the transaction
->currency("XOF") // Any valid currency
->from("22951010200") // Sender phone number with country code préfix
->isWaveAccount(false) //optional. Required only for wave operator
->useOtp(123456) //Required only for Orange Money Burkina. Get it from user after they generate it for your amount by doing: *144*4*6*montant#
->firstName("Iyam") // First name of the sender
->lastName("EVERICH") // Last name of the sender
->merchantOrderId("collection-test00001") //optional. If added we will check if it is uniq for your account
->create();
print_r($collection->getArray());
echo "<br/>" . $collection->getReference();
使用 webhook 收集以在支付处理完成后立即获取响应。
$collection = $momo
->collect()
->amount(2000) //Amount of the transaction
->currency("XOF") // Any valid currency
->from("22951010200") // Sender phone number with country code préfix
->firstName("Iyam") // First name of the sender
->lastName("EVERICH") // Last name of the sender
->webhook("https:// mydomain/payment-status") // Url where we will send you transaction data on progress
->create();
print_r($collection->getArray());
echo "<br/>" . $collection->getReference();
发送货币
简单发放
你还可以使用以下代码向 +22951010200 移动货币钱包发送2000 XOF
$momo = new \Chipdeals\MomoApi\Momo();
$momo->setApiKey("test_FOdigzgSopV8GZggZa89");
$deposit = $momo
->deposit()
->amount(2000) //Amount of the transaction
->currency("XOF") // Any valid currency
->to('22951010200') // Recipient phone number with country code préfix
->isWaveAccount(false) //optional. Required only for CI wave operator
->merchantOrderId("deposit-test00001") //optional. If added we will check if it is uniq for your account
->create();
print_r($deposit->getArray());
echo "<br/>" . $deposit->getReference();
使用 webhook 发放以在存款处理完成后立即获取响应。
$deposit = $momo
->deposit()
->amount(2000) //Amount of the transaction
->currency("XOF") // Any valid currency
->to('22951010200') // Recipient phone number with country code préfix
->webhook("https:// mydomain/payment-status") // Url where we will send you transaction data on progress
->create();
print_r($deposit->getArray());
echo "<br/>" . $deposit->getReference();
获取交易状态
获取引用 dd1e2d17-5c21-4964-b58d-198fd2aac150
的交易的的状态
$momo = new \Chipdeals\MomoApi\Momo();
$momo->setApiKey("test_FOdigzgSopV8GZggZa89");
$reference = "ba32a171-cbea-45fd-8848-ac5b77580be3"
$transaction = $momo->getStatus($reference);
echo $transaction->getReference() . "<br/>";
echo $transaction->getMerchantOrderId() . "<br/>";
echo $transaction->getPhoneNumber() . "<br/>";
echo $transaction->getCountryCode() . "<br/>";
echo $transaction->getOperator() . "<br/>";
echo $transaction->getFirstName() . "<br/>";
echo $transaction->getLastName() . "<br/>";
echo $transaction->getOriginalCurrency() . "<br/>";
echo $transaction->getOriginalAmount() . "<br/>";
echo $transaction->getCurrency() . "<br/>";
echo $transaction->getAmount() . "<br/>";
echo $transaction->getStatus() . "<br/>";
echo $transaction->getStatusMessage() . "<br/>";
echo $transaction->getStatusCode() . "<br/>";
echo $transaction->getStartTimestampInSecond() . "<br/>";
echo $transaction->getEndTimestampInSecond() . "<br/>";
echo $transaction->checkIsCollection() . "<br/>";
echo $transaction->getOperatorReference() . "<br/>";
echo $transaction->getPaymentLink() . "<br/>";
echo "<pre>";
print_r($transaction->getArray());
收集交易数据示例
Array
(
[reference] => ba32a171-cbea-45fd-8848-ac5b77580be3 //reference of the transaction
[merchantOrderId] => collection-test0001 //internal reference of the transaction
[phoneNumber] => 22990630401 //sender phone number
[currency] => XOF //currency
[operator] => MTN //sender operator
[firstName] => Iyam //sender firstName
[lastName] => EVERICH //sender lastName
[originalCurrency] => USD //currency you entered
[originalAmount] => 2000 //amount you entered
[amount] => 1251002 //amount in customer's local currency
[status] => success //transaction status (success|pending|error)
[statusMessage] => Successfully processed transaction //transaction status details are here
[statusCode] => 200 //status of the payment (See Status Message Code section)
[startTimestampInSecond] => 1668184816 //timestamp in second of the moment when the transaction started
[endTimestampInSecond] => 0 //timestamp in second of the moment when the transaction is finished
[operatorReference] => zprojtbtci //reference that operator sent to customer by sms
[isCollection] => true
[paymentLink] => https://pay.wave.com/c/cos-1ewpdr47212cd //payment link that allow you customers to finish the transaction. It is available for operators like Wave
)
发放交易数据示例
Array
(
[reference] => a0903015-a86d-46c3-98ce-bb36639d6d09 //reference of the transaction
[phoneNumber] => 22990630401 //recipient phone number
[currency] => XOF //currency
[operator] => MTN //recipient operator
[firstName] =>
[lastName] =>
[originalCurrency] => XOF //currency you entered
[originalAmount] => 2000 //amount you entered
[amount] => 2000 //amount in customer's local currency
[status] => success //transaction status (success|pending|error)
[statusMessage] => Successfully processed transaction //transaction status details are here
[statusCode] => 200 //status of the disbursement (See Status Message Code section)
[startTimestampInSecond] => 1668229766 //timestamp in second of the moment when the transaction started
[endTimestampInSecond] => 0 //timestamp in second of the moment when the transaction is finished
[operatorReference] => zprojtbkci //reference that operator sent to customer by sms
[isCollection] => false
)
获取您的余额
获取您的Chipdeals账户余额
$momo = new \Chipdeals\MomoApi\Momo();
$momo->setApiKey("test_FOdigzgSopV8GZggZa89");
$balances = $momo->getBalances();
foreach ($balances as $balanceKey => $balance) {
echo $balance->getCountryCode() . "<br/>";
echo $balance->getOperator() . "<br/>";
echo $balance->getCurrency() . "<br/>";
echo $balance->getAmount() . "<br/>";
echo "<pre>";
print_r($balance->getArray());
}
余额示例
Array
(
[countryCode] => BJ
[operator] => MTN
[currency] => XOF
[amount] => 19000
)
Webhook
Webhook是支付集成的重要组成部分。它们允许Chipdeals通知您有关您账户上发生的事件,例如成功的支付或失败的交易。
webhook URL 是您服务器上的一个端点,您可以在此接收有关此类事件的通知。当发生事件时,我们将向该端点发送一个 POST 请求,其中包含包含事件详细信息的 JSON正文,包括事件类型和相关数据。
webhook有效载荷的结构
所有webhook有效载荷都遵循相同的基本结构
- 一个描述事件类型的
event
字段 - 一个
data
对象。该对象的 内容将根据事件而变化,但通常它将包含事件的详细信息,包括- 一个包含交易ID的
reference
- 一个描述交易状态的
status
。可能的值是success
、pending
或error
- 一个包含特定代码的
statusMessageCode
,该代码标识交易的精确状态。查看所有statusMessageCode
- 一个
statusMessage
,包含对交易确切状态的易懂描述 - 交易详情
- 一个包含交易ID的
实现 webhook
在您的服务器上创建 webhook 端点与编写任何其他 API 端点相同,但有一些重要的细节需要注意
响应 webhook 请求 为了确认接收 webhook,您的端点 必须 返回 200
HTTP 状态码。任何其他响应码,包括 3xx
状态码,都将被视为失败。 我们不关心响应体或头部。
请确保在仪表板上启用 webhook 重试。如果我们没有得到 200
状态码(例如,如果您的服务器不可达),我们将在接下来的 36 小时内每 90 分钟重试 webhook 调用。
更多信息
收集和分配参数
- phoneNumber
参数
您可以使用方法 from(phoneNumber: string)
指定收集的 phoneNumber
对于分配,您可以使用方法 to(phoneNumber: string)
指定 phoneNumber
这些方法锁定为包含金钱发送者电话号码的字符串(用于收集)和金钱接收者电话号码的字符串(用于分配)。
电话号码应遵守以下格式
XXXOOOOOOOO
其中三个 X
代表国家电话前缀(例如 229
| 237
),而 O
是国家内的电话号码。 O
的数量可以随国家而变化,但前缀应该是 3。
- currency
参数
您可以使用方法 currency(currency: string)
指定交易的货币
货币应是一个 3 个字符的字符串。
如果您添加的货币不是交易电话号码所在国家的本地货币,我们将将交易金额转换为当地货币。
我们的汇率像市场一样变化。
- amount
参数
您可以使用方法 amount(transactionAmount: number)
指定交易的金额
它是一个数字。
我们将检查您为交易指定的货币是否是电话号码所在国家的本地货币,然后我们将金额转换为当地货币,然后再与客户进行交易。
- firstName
和 lastName
参数
您分别使用方法 firstName(senderFirstName: string)
和 lastName(senderLastName: string)
指定 firstName
和 lastName
这些参数是执行安全收集请求所必需的。
分配不需要它们。
如果您每天发出 3 次未指定 firstName
和/或 lastName
的请求,我们将阻止第 4 次及其后的请求。我们建议您为所有收集请求指定 firstName
和 lastName
。
在沙箱测试中,您对 firstName
和 lastName
的指定没有问题,您可以随意操作 但请注意 Live 环境
状态消息代码
沙箱测试
您可以使用您的 test apikey
或所有用户的测试 apikey:test_FOdigzgSopV8GZggZa89
来进行沙箱请求。
在沙箱中使用的所有有效电话号码都将像实际模式一样发送有效响应。
例如,如果您使用电话号码 22951010581
,您将获得包含状态消息代码 201
(表示 挂起
,更多信息请参见 此处)的响应。几秒钟后,您将获得状态消息代码 202
、203
和 200
(200
表示成功)。
对其他人来说,电话号码也是一样,只有一个小的例外,允许实现者处理错误的情况。
对于 实时 apiKey
和 实时响应 请求,请 联系我们
限制
未加密的收款限制
当您发起收款请求时,您可以选择指定或不需要指定付款人的 firstName
和 lastName
。不指定 firstName
和 lastName
,您可以快速测试。
但是,当未指定 firstName
和 lastName
时,您的收款请求是不安全的。并且您每天最多允许进行 3 次未加密的收款请求。超过的请求将被阻止。
您不能进行超过 500 XOF 的未加密收款请求。
联系我们
请给我们打电话或给我们写信以 获取您的apikey 并开始收款
E-mail: products@chipdeals.me 网站: https://chipdeals.me 电话: +22990630401 WhatsApp: +22990630401
版权(C)2022 Chipdeals Inc - https://chipdeals.me