revenuemonster / sdk
RevenueMonster APIs的PHP SDK
v2.0.4
2023-05-19 14:49 UTC
Requires
- php: ^8.0
- nategood/httpful: ^0.3.2
- rakit/validation: ^1.4.0
- tightenco/collect: ^9.2.0
README
🪣 最小要求
🔨 安装
composer require revenuemonster/sdk
📻 兼容性支持
✨ 支持功能
- 客户端凭证(身份验证)
- 刷新令牌(身份验证)
- 获取商家资料
- 获取商家订阅
- 获取商店
- 通过ID获取商店
- 创建商店
- 更新商店
- 删除商店
- 获取用户资料
- 支付(交易二维码)- 创建交易二维码/URL
- 支付(交易二维码)- 获取交易二维码/URL
- 支付(交易二维码)- 通过代码获取交易二维码/URL
- 支付(交易二维码)- 通过代码获取交易
- 支付(快捷支付)- 支付
- 支付(快捷支付)- 退款
- 支付(快捷支付)- 反冲
- 支付(快捷支付)- 获取所有支付交易
- 支付(快捷支付)- 通过ID获取所有支付交易
- 支付(快捷支付)- 每日结算报告
- 支付(结账)- 创建Web/移动支付(支持新UI)
- 赠送忠诚度积分
- 获取忠诚度会员
- 获取忠诚度会员
- 获取忠诚度会员积分历史
- 发行优惠券
- 作废优惠券
- 通过代码获取优惠券
- 获取优惠券批次
- 通过键获取优惠券批次
- 发送通知(商家)
- 发送通知(商店)
- 发送通知(用户)
- eKYC - Mykad预测
- eKYC - 面部验证
📝 示例
require __DIR__.'/vendor/autoload.php'; use RevenueMonster\SDK\RevenueMonster; use RevenueMonster\SDK\Exceptions\ApiException; use RevenueMonster\SDK\Exceptions\ValidationException; use RevenueMonster\SDK\Request\WebPayment; use RevenueMonster\SDK\Request\QRPay; use RevenueMonster\SDK\Request\QuickPay; // Initialise sdk instance $rm = new RevenueMonster([ 'clientId' => '5499912462549392881', 'clientSecret' => 'pwMapjZzHljBALIGHxfGGXmiGLxjWbkT', 'privateKey' => file_get_contents(__DIR__.'/private_key.pem'), 'isSandbox' => false, ]); // Get merchant profile try { $response = $rm->merchant->profile(); } catch(ApiException $e) { echo "statusCode : {$e->getCode()}, errorCode : {$e->getErrorCode()}, errorMessage : {$e->getMessage()}"; } catch(Exception $e) { echo $e->getMessage(); } // Get merchant subscriptions try { $response = $rm->merchant->subscriptions(); } catch(ApiException $e) { echo "statusCode : {$e->getCode()}, errorCode : {$e->getErrorCode()}, errorMessage : {$e->getMessage()}"; } catch(Exception $e) { echo $e->getMessage(); } // Get merchant's stores try { $response = $rm->store->paginate(10); } catch(ApiException $e) { echo "statusCode : {$e->getCode()}, errorCode : {$e->getErrorCode()}, errorMessage : {$e->getMessage()}"; } catch(Exception $e) { echo $e->getMessage(); } // Get transactions by QR Code try { $qrCode = '732eb1e935983d274695f250dee9eb75'; $response = $rm->payment->transactionsByQrCode($qrCode); } catch(ApiException $e) { echo "statusCode : {$e->getCode()}, errorCode : {$e->getErrorCode()}, errorMessage : {$e->getMessage()}"; } catch(Exception $e) { echo $e->getMessage(); } // Get transactions try { $response = $rm->payment->paginate(5); } catch(ApiException $e) { echo "statusCode : {$e->getCode()}, errorCode : {$e->getErrorCode()}, errorMessage : {$e->getMessage()}"; } catch(Exception $e) { echo $e->getMessage(); } // Find transaction by transaction id try { $transactionId = '100922222732432874823'; $response = $rm->payment->find($transactionId); } catch(ApiException $e) { echo "statusCode : {$e->getCode()}, errorCode : {$e->getErrorCode()}, errorMessage : {$e->getMessage()}"; } catch(Exception $e) { echo $e->getMessage(); } // Find transaction by order id try { $orderId = '1234'; $response = $rm->payment->findByOrderId($orderId); } catch(ApiException $e) { echo "statusCode : {$e->getCode()}, errorCode : {$e->getErrorCode()}, errorMessage : {$e->getMessage()}"; } catch(Exception $e) { echo $e->getMessage(); } // create QR pay try { $qrPay = new QRPay(); $qrPay->currencyType = 'MYR'; $qrPay->amount = 100; $qrPay->isPreFillAmount = true; $qrPay->order->title = '服务费'; $qrPay->order->detail = 'testing'; $qrPay->method = []; $qrPay->redirectUrl = 'https://shop.v1.mamic.asia/app/index.php?i=6&c=entry&m=ewei_shopv2&do=mobile&r=order.pay_rmwxpay.complete&openid=ot3NT0dxs4A8h4sVZm-p7q_MUTtQ&fromwechat=1'; $qrPay->storeId = '1553067342153519097'; $qrPay->type = 'DYNAMIC'; $response = $rm->payment->qrPay($qrPay); } catch(ApiException $e) { echo "statusCode : {$e->getCode()}, errorCode : {$e->getErrorCode()}, errorMessage : {$e->getMessage()}"; } catch(Exception $e) { echo $e->getMessage(); } // create Web payment try { $wp = new WebPayment; $wp->order->id = '10020'; $wp->order->title = 'Testing Web Payment'; $wp->order->currencyType = 'MYR'; $wp->order->amount = 100; $wp->order->detail = ''; $wp->order->additionalData = ''; $wp->storeId = "1553067342153519097"; $wp->redirectUrl = 'https://google.com'; $wp->notifyUrl = 'https://google.com'; $wp->layoutVersion = 'v1'; $response = $rm->payment->createWebPayment($wp); echo $response->checkoutId; // Checkout ID echo $response->url; // Payment gateway url } catch(ApiException $e) { echo "statusCode : {$e->getCode()}, errorCode : {$e->getErrorCode()}, errorMessage : {$e->getMessage()}"; } catch(ValidationException $e) { var_dump($e->getMessage()); } catch(Exception $e) { echo $e->getMessage(); } // create Quick pay try { $qp = new QuickPay; $qp->authCode = '281011026026517778602435'; $qp->order->id = '443'; $qp->order->title = '【原味系列】 猫山王榴'; $qp->order->currencyType = 'MYR'; $qp->order->amount = 10; $qp->order->detail = ''; $qp->order->additionalData = 'SH20190819100656262762'; $qp->ipAddress = '8.8.8.8'; $qp->storeId = "1553067342153519097"; $response = $rm->payment->quickPay($qp); } catch(ApiException $e) { echo "statusCode : {$e->getCode()}, errorCode : {$e->getErrorCode()}, errorMessage : {$e->getMessage()}"; } catch(ValidationException $e) { var_dump($e->getMessage()); } catch(Exception $e) { echo $e->getMessage(); }
eKYC模块
Revenue Monster eKYC(电子了解你的客户)模块提供了完善注册体验的功能。
此模块中所有方法仅接受base64数据URL中的数据部分。
例如,你可能有一个如下所示的base64字符串,只需发送数据部分。
Format - data:[<mediatype>][;base64],<data>
Example - data:image/jpeg;base64,/9j/4AAQSkZJRgABAQE......
Data Portion - /9j/4AAQSkZJRgABAQE......
eKYC MyKad
此方法将接受mykad图像并返回用于在活动SDK中使用的请求ID。
try { $mykad = new EkycMyKad(); $mykad->base64Image = file_get_contents(__DIR__.'/mykad.txt'); $response = $rm->ekyc->call($mykad); } catch(Exception $e) { echo $e->getMessage(); }
面部验证
此方法将识别并验证两幅图像上的人脸是否为同一人。
try { $image = file_get_contents(__DIR__.'/face.txt'); $face = new VerifyFace(); $face->base64Image1 = $image; // image 1 $face->base64Image2 = $image; // image 2 $response = $rm->ekyc->call($face); } catch(Exception $e) { echo $e->getMessage(); }
获取eKYC结果
此方法接受来自活动SDK的返回的ekycId
参数。它将返回完整的eKYC结果。
try { $request = new EkycGetResult(); $request->id = "62201d52239b18052126e289"; $ekycResult = $rm->ekyc->call($request); } catch(Exception $e) { echo $e->getMessage(); }
获取MyKad结果
此方法接受来自EkycMyKad
方法的返回的id
参数,或来自EkycGetResult
方法的mykadRequestId
参数。它将返回从MyKad识别出的完整数据。
try { $request = new EkycGetMyKadResult(); $request->id = $ekycResult->mykadRequestId; $response = $rm->ekyc->call($request); } catch(Exception $e) { echo $e->getMessage(); }