otifsolutions / laravel-airtime
一款多功能的软件包,使用第三方服务向用户/手机号码发送余额/充值
Requires
This package is auto-updated.
Last update: 2024-09-25 16:17:42 UTC
README
Laravel Airtime
一款多功能的软件包,使用第三方服务向用户/手机号码发送余额/充值
需求
laravel >= 8.0
php >= 7.4
通过Composer安装
🔗 Composer 是安装此软件包所必需的
composer require otifsolutions/laravel-airtime
我们已经使用了 🔗 Setting 软件包由 🔗 OTIF Solutions 来设置
我们使用的密钥
\OTIFSolutions\Laravel\Settings\Models\Setting::set('key', 'value', 'type');
以获取针对该 key
🔑 的特定值
\OTIFSolutions\Laravel\Settings\Models\Setting::get('key');
该软件包使用以下四个列出的服务,请考虑该特定服务是 启用
还是 禁用
。或者,您可以通过将其设置为 true
来启用它。别忘了添加 bool
。
注意 📚
默认情况下,所有这些服务都是 禁用
的。您必须通过 Setting::set
启用您选择的服务。请记住,不要忘记将第三个参数添加为 bool
,它定义了键的类型。
不要直接在您的代码中设置密钥,但明智的做法是使用 php artisan tinker
,然后运行您选择的服务命令
AND
要检查服务是启用还是禁用,请执行
Setting::get('service_name_service')
MySQL表存储引擎
请注意,将数据放入或从MySQL表拉出时,使用不同的MySQL存储引擎会有所不同。默认当前引擎为 InnoDB。如果您不知道这些存储引擎之间的区别,请访问 🔗 MyIsam & InnoDB。要将引擎切换到 MyISAM,请执行以下操作 👇 并将键 myisam_engine
设置为 true
\OTIFSolutions\Laravel\Settings\Models\Setting::set('myisam_engine', false, 'bool');
最后,使用此命令 👇 运行迁移
php artisan migrate
这将运行软件包的迁移,对于表 airtime_currencies
的迁移将仅在其他迁移保持等待运行时运行,它们将仅在特定服务启用时(通过设置软件包 使为true)运行。
此软件包中的Artisan命令
要检查此 airtime
软件包中可用的所有命令,只需执行此命令,然后查看键 sync:xxxxxxxx_xxxxxx_xxxxxxx
php artisan
如果您在未激活/启用特定服务的情况下执行特定服务的同步数据命令,该软件包将不允许您这样做。它会要求您首先启用它。
目录
Reloadly
该服务处理来自全球800多家运营商的用户之间的充值交易,维护所有运营商和用户之间成功/失败交易的确切记录
✔️ 启用Reloadly服务
\OTIFSolutions\Laravel\Settings\Models\Setting::set('reloadly_service', true, 'bool');
用法
在🔗 Reloadly注册,并从🔗 Reloadly/keys获取密钥,这些密钥将与套餐一起使用,您必须通过tinker
捕获这些密钥并将其提供给套餐。第三个是模式,是否为LIVE
或TEST
。我们使用🔗 Setting套餐设置密钥
设置realaodly凭据的命令
\OTIFSolutions\Laravel\Settings\Models\Setting::set('reloadly_api_key', 'API Client ID');
\OTIFSolutions\Laravel\Settings\Models\Setting::set('reloadly_api_secret', 'API Client Secret');
如果与沙盒一起工作,模式将为TEST
,否则为LIVE
\OTIFSolutions\Laravel\Settings\Models\Setting::set('reloadly_api_mode', 'MODE');
安装包后,您将拥有artisan命令,点击以下链接
php artisan sync:reloadly
调度命令
它将同步所有来自响应的数据。要安排它,请访问您的项目App\Console\Kernel
类,在
protected function schedule(Schedule $schedule) { $schedule->command('sync:reloadly')->weekly(); // $schedule->command('sync:reloadly')->monthly(); // $schedule->command('sync:reloadly')->daily(); }
您甚至可以安排此命令在特定日期和时间运行。有关更多信息,请访问:链接 安排Artisan命令
如何发送交易
要发送交易,创建一个具有属性的ReloadlyTransaction
对象,将其作为参数传递给Reloadly
辅助类方法的sendTopup(ReloadlyTransaction $reloadlyTransactionObj)
并执行它
$rdHelperObj = Reloadly::Make($key, $secred, $mode); $rdTransaction = ReloadlyTransaction::create([ 'operator_id' => 1, // the operator id, under which operator the transaction is being from total 800+ operators 'is_local' => false, // Indicates either transaction is in operator currency in which customer will get airtime or its in currency of Reloadly account being used 'topup' => 100, // amount in receiving currency 'amount' => 125, // amount in sending currency 'number' => '00923219988771', // the connected phone number to which transaction has to be made 'sender_currency' => 'PKR', // currency from which transaction is being made 'destination_currency' => 'PKR' // currency of transaction receiving channel/user ]); $rdHelperObj->sendTopup($rdTransaction);
其他字段需要在每个交易对象上填充一些values/jsons
如何发送礼品卡
要发送交易,创建一个具有属性的ReloadlyGiftCardTransaction
对象,在该对象上调用sendTransaction()
方法。
$rdHelperObj = Reloadly::Make($key, $secred, $mode); $rdHelperObj->getGiftToken(); $giftCard = ReloadlyGiftCardProduct::find($request['gift_id']); // selected gift card $rdTransaction = ReloadlyGiftCardTransaction::create([ 'user_id' => $user['id'], // user who is using the service 'email' => $request['email'], // customr/user for whick service is used 'invoice_id' => $invoice['id'], // invoice for the record 'product_id' => $giftCard['id'], 'product' => $giftCard, // the reloadly gift card 'recipient_currency_id' => $recipientCurrency['id'], // currency from which transaction is being made 'sender_currency_id' => $senderCurrency['id'], // currency of transaction receiving channel/user 'sender_amount' => $giftCard['fixed_sender_denominations'][$paymentIndex] + $giftCard['sender_fee'], // You can add your fee as well 'reloadly_fee' => $giftCard['sender_fee'], // The fee of the gift card 'recipient_amount' => $giftCard['fixed_recipient_denominations'][$request['selected_index']], // The price of the gift card 'reference' => Str::random(10), ]); $rdTransaction->sendTransaction();
如何支付公用事业账单
要发送交易,创建一个具有属性的ReloadlyUtilityTransaction
对象,将其作为参数传递给Reloadly
辅助类方法的sendTopup(ReloadlyTransaction $reloadlyTransactionObj)
并执行它
$rdHelperObj = Reloadly::Make($key, $secred, $mode); $rdHelperObj->getUtilityToken(); $utilityBiller = ReloadlyUtility::find($request['biller_id']); // The selected biller for which bill is paying. $rdTransaction = ReloadlyUtilityTransaction::create([ 'user_id' => $user['id'], // user who is using the service 'utility_id' => $utilityBiller['id'], // user who is using the service 'subscriber_account_number' => $request['account_number'], // customr/user no. for which service is used 'is_local' => $request['is_local'], // Local amount or international amount 'amount' => 10000, // The amount paid to the biller 'reference_id' => Str::random(10), ]); $rdHelperObj->payUtilityBill($rdTransaction);
现在您需要添加以下行来确认交易
$rdHelperObj->confirmReloadlyUtilityTransaction($rdTransaction);
或者运行以下命令
php artisan sync:reloadly_utility_transaction
您可以在app/Console/Kernel.php
中将此命令设置为每分钟运行一次
$schedule->command('sync:reloadly_utility_transaction')->everyMinute();
此服务的Artisan同步命令是如何工作的
- 首先检查此服务是否启用
- 运行迁移后检查凭证
- 使用凭证生成令牌,获取余额并设置余额
- 软删除国家以与活动国家同步
- 获取运营商并与MySQL表同步
- 同步促销活动
- 然后同步折扣
Reloadly的模式关系
值充值
该服务与上述服务相同,只需访问网站,注册,获取user_id
和password
,通过命令将其提供给套餐。点击命令以同步来自API
响应的数据。
✔️ 启用Value-topup服务
\OTIFSolutions\Laravel\Settings\Models\Setting::set('value_topup_service', true, 'bool');
命令
只需通过命令简单提供user_id
和password
。使用tinker
✔️ 关于user_id
\OTIFSolutions\Laravel\Settings\Models\Setting::set('value_topup_user_id', 'userid');
✔️ 关于密码
\OTIFSolutions\Laravel\Settings\Models\Setting::set('value_topup_password', 'password');
✔️ 关于模式测试/实时(注意测试/实时模式)
\OTIFSolutions\Laravel\Settings\Models\Setting::set('value_topup_api_mode', 'MODE');
✔️ 同步数据的Artisan命令
php artisan sync:value_topup
✔️ 检查状态的Artisan命令
php artisan sync:value_topup_status
发送交易
此服务有四种发送交易的方法,分别命名为topupTransaction
、pinTransaction
、cardTransaction
和billPayTransaction
。尽管发送交易的格式相同,因为有一个名为value_topup_transactions
的表包含所有交易。以下是发送交易的整体视图👇
$vtObj = ValueTopup::Make()->setCredentials($userId, $password, $mode = 'LIVE'); // will return on object containing all the methods & becareful with the mode $vtTransactionObj = ValueTopupTransaction::create([ 'category_id' => 2, // foreign key for category to indicate which type of transaction is created here like Airtime, Pin etc 'country_id' => 9, // country id, like 9 for Pakistan, 13 for Panama 'operator_id' => 16, // operator id, under which operator the transaction is being made 'product_id' => 1031, // id of particular product/package ranging more than 100, like 1 for product '8ta South Africa 5.40 USD' 'reference' => '166064462062fb6d0c4ab37', // user generated truly unique string of 50 characters, Correlation ID which you send in actual topup api method 'topup' => 100, // it is by default in Customer Wallet Currency 'amount' => 200, // amount in sending currency 'number' => '00923229988770', // number to which we are sending transaction, destination phone number 'sender_currency' => 'PKR', // currency type of sender user 'receiver_currency' => 'PKR', // receiving currency, destination currency ]); // you can generate reference by uniqid(time())
其他字段需要在每个交易对象上填充一些values/jsons
其他交易方法
现在👇是提供的四种交易方法的具体细节
充值交易
topupTransaction($transaction)
此方法接受一些填充的
ValueTopupTransaction
对象字段,如$vtTransactionObj[product][sku_id]
、amount
、number
、reference
、number
、receiver_currency
和sender_currency
,它击中后端的/transaction/topup
URI
$vtObj->topupTransaction($vtTransactionObj);
PIN交易
pinTransaction($transaction)
此方法接受带有
$obj[product][sku_id]
和reference
的$transactionObj
,并在后端击中/transaction/pin
卡片交易
cardTransaction($transaction, $firstName, $lastName, $email)
此交易方法除了需要姓名、姓氏和电子邮件外,在
$transactionObj
中还需要$obj[product][sku_id]
、amount
、reference
,并在后台调用/transaction/giftcard/order
接口。
账单支付交易
billPayTransaction($transaction)
此方法接受包含
$obj[product][sku_id]
、amount
、number
、reference
和sender_currency
的$transactionObj
,并在后端使用/transaction/billpay/
接口。
同步命令背后的场景是如何工作的
- 检查服务是否启用,然后逐个运行其迁移。
- 然后检查凭证并生成令牌。
- 同步操作员
- 同步产品
- 同步产品描述
- 然后从 JSON 文件中同步国家数据
ValueTopup的模式关系
Ding Connect
此服务的后台流程也是一样的,从 operator 向 user 发送 balance/topup,并在数据库中创建交易记录。您只需提供 token/key 即可使其生效。
用法
✔️ 启用 Ding-connect 服务
\OTIFSolutions\Laravel\Settings\Models\Setting::set('ding_connect_service', true, 'bool');
命令
提供令牌 👇
\OTIFSolutions\Laravel\Settings\Models\Setting::set('ding_connect_token', 'token', 'string');
在 setting/giving 令牌后,您可以成功执行以下 artisan 命令
,它将同步 countries、operators 和 products。该过程将在后台运行,只需执行命令并保持标签页打开即可。
php artisan sync:ding_connect
发送交易
要使用 Ding Connect Service 发送交易,首先通过将 API_Key
或 Token
传递给 DingConenct::Make()
方法来创建辅助类的 obj,它将返回一个具有 sendTranser()
方法的对象,如下所示 👇
$dingConenctObj = DingConnect::Make($tokenOrKey); $dcTransactionObj = DingConenctTransaction::create([ 'operator_id' => 1, // id from any total 600+ operators under which transaction is made, like 1 for operator name 'Digicel Guyana' 'product_id' => 1, // the product/package id from one of 3300+ products which is being baught 'sku_code' => 'GY_DC_TopUp', // unique sku code provided by API to indicate which product is being bought. 'send_value' => 200, // the amount to be sent 'send_currency_code' => 'PKR', // the currency of sender side 'number' => '00923219988771', // sender phone number sample 'ref' => 'reference', // distributor reference ]); $dingConenctObj->sendTransfer($dcTransactionObj);
其他字段需要在每个交易对象上填充一些values/jsons
同步命令在行动中是如何工作的
- 检查此服务是否启用
- 运行其迁移
- 检查凭证,如果错误则显示用户友好的错误消息
- 从 JSON 文件中同步国家数据
- 同步国家
name
、iso2
和dial_code
- 同步操作员
- 同步产品
Ding Connect的模式关系
D Tone
此服务背后的概念相同,用于向用户发送 topup/balance
。
如何使用此服务
要使用此服务,通过 Setting::set()
设置 dtone_currency
,它将具有 EUR、USD 或 PKR 等货币名称。因此,在运行其他 D-Tone 命令之前在此处正确设置它 👇
\OTIFSolutions\Laravel\Settings\Models\Setting::set('dtone_currency', 'currency_name', 'string');
✔️ 启用 D-Tone 服务
\OTIFSolutions\Laravel\Settings\Models\Setting::set('dtone_service', true, 'bool');
设置和命令
首先设置 👇
\OTIFSolutions\Laravel\Settings\Models\Setting::set('dtone_tshop_username', 'value-username', 'string');
然后 👇
\OTIFSolutions\Laravel\Settings\Models\Setting::set('dtone_tshop_token', 'value-token', 'string');
要使用 D-Tone
平台同步数据,执行此命令 👇
php artisan sync:dtone
发送交易
要使用此服务发送交易,创建 DToneTransaction
对象,将其作为参数传递给辅助类的 DTone
方法 sendTransfer()
,以下代码段将有助于理解此代码:
$dToneObj = DTone::Make($username, $token); $dtoneTransactionObj = DToneTransaction::create([ 'operator_id' => 1, // id from any operators available for this service 'product_id' => 1, // id of any product/package which is being baught by the user 'sender_phone_no' => '00923219988771', // the phone number which is about to send the transaction 'number' => '00923217878776', // transaction receiver phone number, destination phone number 'product' => 'some-type', // the type of package/product user has baught ]); $dToneObj->sendTransfer($dtoneTransactionObj);
其他字段需要在每个交易对象上填充一些values/jsons
同步命令是如何工作的
- 检查 D-Tone 货币和服务
- 运行迁移并检查凭证
- 在
name
、dial_code
和t_shop_id
中同步国家 - 同步操作员
- 同步产品
D Tone服务的模式关系
许可证
MIT 许可证(MIT)。有关更多信息,请参阅 🔗 许可证文件