instamojo/instamojo-php

这是 instamojo-php 的 composer 封装

1.0 2020-09-08 10:18 UTC

This package is not auto-updated.

Last update: 2024-09-14 04:11:22 UTC


README

使用 PHP 程序创建、编辑和删除 Instamojo 上的链接。

注意:如果您使用此封装器与我们的沙盒环境 https://test.instamojo.com/,则在初始化时将第三个参数传递给 Instamojo 类为 true。相同的环境的 client_idclient_secret 令牌可以从 https://test.instamojo.com/developers/ 获取(详情:测试或沙盒账户)。

$authType = "app/user" /**Depend on app or user based authentication**/

$api = Instamojo\Instamojo::init($authType,[
        "client_id" =>  'XXXXXQAZ',
        "client_secret" => 'XXXXQWE',
        "username" => 'FOO', /** In case of user based authentication**/
        "password" => 'XXXXXXXX' /** In case of user based authentication**/

    ],true); /** true for sandbox enviorment**/

通过 Composer 安装

php composer.phar require instamojo/instamojo-php

注意:如果您不使用 Composer,则直接将 src 目录的内容包含到您的项目中。

用法

$api = Instamojo\Instamojo::init($authType,[
        "client_id" =>  'XXXXXQAZ',
        "client_secret" => 'XXXXQWE',
        "username" => 'FOO', /** In case of user based authentication**/
        "password" => 'XXXXXXXX' /** In case of user based authentication**/

    ]);

文档

请参阅文档以获取详细说明

目录

创建新的支付请求

try {
    $response = $api->createPaymentRequest(array(
        "purpose" => "FIFA 16",
        "amount" => "3499",
        "send_email" => true,
        "email" => "foo@example.com",
        "redirect_url" => "http://www.example.com/handle_redirect.php"
        ));
    print_r($response);
}
catch (Exception $e) {
    print('Error: ' . $e->getMessage());
}

这将返回一个包含刚刚创建的支付请求详细信息的 JSON 对象,其中包含 longurl 键,为您提供 instamojo-payment-url。

推荐无缝结账选项

您可以使用基于 JS 的无缝结账库,仅使用在 createPaymentRequest() 中获得的 instamojo-payment-url 在您的网页上渲染 Instamojo 结账表单并收集支付。要了解更多信息,请点击这里

支付请求创建参数

必需

  • purpose:支付请求的目的。
  • amount:请求的金额。最低金额为 9,最高金额为 200000。

可选

  • buyer_name:付款人的姓名。
  • email:付款人的电子邮件。
  • phone:付款人的电话号码。
  • send_email:如果您指定了电子邮件,则将此设置为 true 以向付款人发送电子邮件。如果没有指定电子邮件,则引发错误。(默认值:false
  • send_sms:如果您指定了电话号码,则将此设置为 true 以向付款人发送短信。如果没有指定电话号码,则引发错误。(默认值:false
  • redirect_url:将此设置为您的网站上的感谢页面。在成功付款后,买家将被重定向到此页面。
  • webhook:将此设置为可以接受 Instamojo 服务器在成功付款后发出的 POST 请求的 URL。
  • allow_repeated_payments:要禁止在支付请求上多次成功支付,请为此字段传递 false。如果设置为 false,则第一个成功付款后,链接将不再公开可访问,尽管您仍然可以使用 API 访问它(默认值:true)。
  • partner_fee_type:允许您从您促成的付款中分得一部分。对于固定费用,将其设置为fixed,对于百分比费用,将其设置为percent
  • partner_fee:这描述了您将收取的费用。可以是固定金额,也可以是原始金额的百分比,具体取决于partner_fee_type的值。
  • mark_fulfilled:标志以确定您是否要将付款挂起,直到您明确履行。如果mark_fulfilledTrue,则付款将支付给商家。如果mark_fulfilledFalse,则付款将挂起,直到您明确履行付款。有关如何履行付款,请参阅下面的履行付款。
  • expires_at:在UTC时间戳之后,付款请求将过期。最大值是600秒。默认为Null。

获取付款请求的状态或详细信息

try {
    $response = $api->getPaymentRequestDetails(['PAYMENT REQUEST ID']);
    print_r($response);
}
catch (Exception $e) {
    print('Error: ' . $e->getMessage());
}

这将返回一个JSON对象,包含付款请求及其相关付款的详细信息。付款的键是'payments'

在这里['付款请求ID']createPaymentRequest()查询返回的'id'键的值。

获取所有付款请求的列表

try {
    $response = $api->getPaymentRequests();
    print_r($response);
}
catch (Exception $e) {
    print('Error: ' . $e->getMessage());
}

这将返回一个包含迄今为止创建的付款请求的数组。请注意,此查询不会返回与单个付款请求相关的付款。

getPaymentRequests()还接受分页的可选参数。

getPaymentRequests($limit=null, $page=null)

例如

$response = $api->getPaymentRequests(50, 1);

获取所有付款的列表

try {
    $response = $api->getPayments();
    print_r($response);
}
catch (Exception $e) {
    print('Error: ' . $e->getMessage());
}

这将返回包含迄今为止付款详细信息的数组。

getPayments()还接受分页的可选参数。

getPayments($limit=null, $page=null)

例如

$response = $api->getPayments(50, 1);

获取付款的详细信息

try {
    $response = $api->getPaymentDetails(['PAYMENT ID']);
    print_r($response);
}
catch (Exception $e) {
    print('Error: ' . $e->getMessage());
}

这将返回包含付款详细信息的JSON对象。

在这里['付款ID']getPayments()查询返回的'id'键的值。

创建网关订单

try {
    $response = $api->createGatewayOrder(array(
      "name" => "XYZ",
      "email" => "abc@foo.com",
      "phone" => "99XXXXXXXX",
      "amount" => "200",
      "transaction_id" => 'TXN_ID', /**transaction_id is unique Id**/
      "currency" => "INR"
    ));
    print_r($response);
}
catch (Exception $e) {
    print('Error: ' . $e->getMessage());
}

这将返回一个JSON对象,其中包含订单的详细信息(在order键中)和付款选项(在payment_options键中)。

为付款请求创建网关订单

try {
    $response = $api->createGatewayOrderForPaymentRequest($payment_request_id, array(
      "name" => "XYZ",
      "email" => "abc@foo.com",
      "phone" => "99XXXXXXXX",
    ));
    print_r($response);
}
catch (Exception $e) {
    print('Error: ' . $e->getMessage());
}

$payment_request_idcreatePaymentRequest()方法中获得的id键的值。

这将返回包含创建的order_id键的JSON对象。

获取网关订单的详细信息

try {
    $response = $api->getGatewayOrder(['ORDER ID']);
    print_r($response);
}
catch (Exception $e) {
    print('Error: ' . $e->getMessage());
}

这将返回包含网关订单详细信息的JSON对象。

在这里['订单ID']createGatewayOrder()查询返回的'id'键的值。

获取所有网关订单的列表

try {
    $response = $api->getGatewayOrders();
    print_r($response);
}
catch (Exception $e) {
    print('Error: ' . $e->getMessage());
}

这将返回包含迄今为止网关订单详细信息的数组。

getGatewayOrders()还接受分页的可选参数。

getGatewayOrders($limit=null, $page=null)

例如

$response = $api->getGatewayOrders(50, 1);

为付款创建退款

try {
    $response = $api->createRefundForPayment($payment_id, array(
      "type" => "RFD",
      "body" => "XYZ reason of refund",
      "refund_amount" => "10",
      "transaction_id" => "TNX_XYZ"
    ));
    print_r($response);
}
catch (Exception $e) {
    print('Error: ' . $e->getMessage());
}

这将返回包含退款详细信息(在refund键中)的JSON对象。

必需参数

  • type:三个字母的简码,用于标识退款的原因,字符串类型。
  • body:解释退款的附加文本,字符串类型。
  • refund_amount:可以使用此字段指定退款金额,字符串类型。
  • transaction_id:为防止API重放导致的重复案例创建,字符串类型。

type参数的有效值

  • RFD:重复/延迟付款。
  • TNR:产品/服务不再可用。
  • QFL:客户不满意。
  • QNR:产品丢失/损坏。
  • EWN:数字下载问题。
  • TAN:活动已取消/更改。
  • PTH:上述问题未描述。

获取退款详细信息

try {
    $response = $api->getRefundDetails(['REFUND ID']);
    print_r($response);
}
catch (Exception $e) {
    print('Error: ' . $e->getMessage());
}

这将返回包含退款详细信息的JSON对象。

获取所有退款列表

try {
    $response = $api->getRefunds();
    print_r($response);
}
catch (Exception $e) {
    print('Error: ' . $e->getMessage());
}

这将返回包含迄今为止退款详细信息的数组。

getRefunds()还接受分页的可选参数。

getRefunds($limit=null, $page=null)

例如

$response = $api->getRefunds(50, 1);

常见问题解答