bayonet/bayonet-php

2.0.0 2018-03-26 00:56 UTC

This package is not auto-updated.

Last update: 2024-09-29 03:10:14 UTC


README

Latest Stable Version License

Bayonet

Bayonet使公司能够基于历史支付,向全球数据库提供和咨询关于在线消费者信誉的信息。今天开始做出更明智的商业决策。

简介

Bayonet的API基于REST,公开了HTTP请求的端点。它设计有可预测的资源URL,并使用标准的HTTP响应代码来指示操作的成果。请求和响应负载格式化为JSON。

关于服务

Bayonet提供了一个信任和保护生态系统,公司可以相互协作,共同打击网络欺诈。我们提供了一个安全平台,用于共享和咨询数据,以了解消费者是否与欺诈活动有关或有无欺诈记录。通过运行算法将不同交易中看到的参数链接起来的不同技术被采用,这些技术由连接到生态系统的公司提供,以建立消费者档案。通过查询Bayonet的API,可以实时获取由公司本身提供的数据响应,以便您的风险评估过程进行分析并做出更好的决策。

Bayonet的API详细信息

此README中显示的示例仅用于展示此SDK的功能。有关详细集成流程和何时发送哪个API调用,请参阅Bayonet API文档

入门

要求

要使用此SDK,请确保

  • 您的系统已安装PHP 5.4或更高版本。
  • 您有Bayonet团队提供的API密钥(沙盒和/或实时)。

Composer

  1. 在您的composer.json文件中添加依赖项'bayonet-php'

    "require": {
        ...
        "bayonet/bayonet-php": "2.0.*"
        ...
    }
    

    运行Composer获取依赖项

    composer update
  2. 使用Composer自动加载加载依赖项

    require_once('vendor/autoload.php');

手动安装

  1. 如果您不使用Composer,请下载最新版本。将其提取到您的项目根目录下,命名为bayonet-php的文件夹中。使用init.php文件加载Bayonet依赖项

    require 'bayonet-php/init.php';
  2. BayonetClient使用Guzzle作为依赖项。请确保您已下载并将Guzzle包含到您的项目中

    require 'guzzle/autoloader.php';

如果您使用Composer,上述依赖项将自动处理。如果您选择手动安装,您需要确保依赖项可用。

用法

一旦您已配置Bayonet的SDK,您可以使用以下语法调用API。遵循您要集成的产品的特定指南

电子商务

  • 初始化电子商务客户端

    $bayonet = new Bayonet\EcommerceClient([
      'api_key' => 'your_api_key',
      'version' => 2
    ]);

    您还可以使用环境变量来加载API密钥

    export BAYONET_API_KEY=your_api_key
  • 咨询API

    $bayonet->consult([
      'body' => [
        'channel' => 'ecommerce',
        'email' => 'example@bayonet.io',
        'consumer_name' => 'Example name',
        'consumer_internal_id' => '<your internal ID for this consumer>',
        'cardholder_name' => 'Example name',
        'telephone' => '1234567890',
        'card_number' => '4111111111111111',
        'transaction_amount' => 999.00,
        'currency_code' => 'MXN',
        'shipping_address' => [
          'line_1' => 'example line 1',
          'line_2' => 'example line 2',
          'city' => 'Mexico City',
          'state' => 'Mexico DF',
          'country' => 'MEX',
          'zip_code' => '64000'
        ],
        'billing_address' => [
          'line_1' => 'example line 1',
          'line_2' => 'example line 2',
          'city' => 'Mexico City',
          'state' => 'Mexico DF',
          'country' => 'MEX',
          'zip_code' => '64000'
        ],
        'payment_method' => 'card',
        'order_id' => '<your internal ID for this order>',
        'transaction_id' => '<your internal ID for this transaction>',
        'payment_gateway' => 'stripe',
        'coupon' => 'discount_buen_fin',
        'expedited_shipping' => true,
        'products' => [
          [
            'product_id' => '1',
            'product_name' => 'product_1',
            'product_price' => 500.00,
            'product_category' =>'example category'
          ],
          [
            'product_id' => '2',
            'product_name' => 'product_2',
            'product_price' => 499.00,
            'product_category' =>'example category'
          ]
        ],
        'bayonet_fingerprint_token' => '<token generated by Bayonet fingerprinting JS>'
      ],
      'on_success' => function($response) {
        print_r($response);
      },
      'on_failure' => function($response) {
        print_r($response);
      }
    ]);
  • 更新交易API

    $bayonet->update_transaction([
      'body' => [
        'transaction_status' => 'success',
        'transaction_id' => '<your internal ID for this transaction (as sent in the consult step)>',
        ...
      ],
      'on_success' => function($response) {
        print_r($response);
      },
      'on_failure' => function($response) {
        print_r($response);
      }
    ]);
  • 历史反馈API

    $bayonet->feedback_historical([
      'body' => [
        'channel' => 'ecommerce',
        'email' => 'example@bayonet.io',
        'consumer_name' => 'Example name',
        'consumer_internal_id' => '<your internal ID for this consumer>',
        'cardholder_name' => 'Example name',
        'telephone' => '1234567890',
        'card_number' => '4111111111111111',
        'transaction_amount' => 999.00,
        'currency_code' => 'MXN',
        'shipping_address' => [
          'line_1' => 'example line 1',
          'line_2' => 'example line 2',
          'city' => 'Mexico City',
          'state' => 'Mexico DF',
          'country' => 'MEX',
          'zip_code' => '64000'
        ],
        'billing_address' => [
          'line_1' => 'example line 1',
          'line_2' => 'example line 2',
          'city' => 'Mexico City',
          'state' => 'Mexico DF',
          'country' => 'MEX',
          'zip_code' => '64000'
        ],
        'payment_method' => 'card',
        'transaction_id' => '<your internal ID for this transaction>',
        'payment_gateway' => 'stripe',
        'coupon' => 'discount_buen_fin',
        'expedited_shipping' => true,
        'products' => [
          [
            'product_id' => '1',
            'product_name' => 'product_1',
            'product_price' => 500.00,
            'product_category' =>'example category'
          ],
          [
            'product_id' => '2',
            'product_name' => 'product_2',
            'product_price' => 499.00,
            'product_category' =>'example category'
          ]
        ],
        'bayonet_fingerprint_token' => '<token generated by Bayonet fingerprinting JS>',
        'transaction_time' => 1476012879,
        'transaction_status' => 'success',
      ],
      'on_success' => function($response) {
          print_r($response);
      },
      'on_failure' => function($response) {
          print_r($response);
      }
    ]);

贷款

  • 初始化贷款客户端

    $bayonet = new Bayonet\LendingClient([
      'api_key' => 'your_api_key',
      'version' => 2
    ]);

    您还可以使用环境变量来加载API密钥

    export BAYONET_API_KEY=your_api_key
  • 报告交易(收到贷款请求)

    $bayonet->report_transaction([
      'body' => [
        'email' => 'example@bayonet.io',
        'consumer_name' => 'Example name',
        'consumer_internal_id' => '<your internal ID for this consumer>',
        'telephone_fixed' => '1234567890',
        'telephone_mobile' => '1234567891',
        'telephone_reference_1' => '1234567892',
        'telephone_reference_2' => '1234567893',
        'telephone_reference_3' => '1234567894',
        'rfc' => 'Example RFC',
        'curp' => 'Example CURP',
        'clabe' => 'Example CLABE',
        'address' => [
          'line_1' => 'example line 1',
          'line_2' => 'example line 2',
          'city' => 'Mexico City',
          'state' => 'Mexico DF',
          'country' => 'MEX',
          'zip_code' => '64000'
        ],
        'bayonet_fingerprint_token' => '<token generated by Bayonet fingerprinting JS>',
        'transaction_category' => 'p2p_lending',
        'transaction_id' => '<your internal ID for this transaction>',
        'transaction_time' => 1476012879
      ],
      'on_success' => function($response) {
        print_r($response);
      },
      'on_failure' => function($response) {
        print_r($response);
      }
    ]);
  • 报告交易(收到贷款请求)+ 咨询

    这允许您报告一笔交易(solicitud)并同时在Bayonet中进行咨询。与上述方法(报告交易)的唯一区别是,此方法还将返回咨询响应

    $bayonet->report_transaction_and_consult([
      'body' => [
        'email' => 'example@bayonet.io',
        'consumer_name' => 'Example name',
        'consumer_internal_id' => '<your internal ID for this consumer>',
        'telephone_fixed' => '1234567890',
        'telephone_mobile' => '1234567891',
        'telephone_reference_1' => '1234567892',
        'telephone_reference_2' => '1234567893',
        'telephone_reference_3' => '1234567894',
        'rfc' => 'Example RFC',
        'curp' => 'Example CURP',
        'clabe' => 'Example CLABE',
        'address' => [
          'line_1' => 'example line 1',
          'line_2' => 'example line 2',
          'city' => 'Mexico City',
          'state' => 'Mexico DF',
          'country' => 'MEX',
          'zip_code' => '64000'
        ],
        'bayonet_fingerprint_token' => '<token generated by Bayonet fingerprinting JS>',
        'transaction_category' => 'p2p_lending',
        'transaction_id' => '<your internal ID for this transaction>',
        'transaction_time' => 1476012879
      ],
      'on_success' => function($response) {
        print_r($response);
      },
      'on_failure' => function($response) {
        print_r($response);
      }
    ]);
  • 咨询(咨询交易中的人物)

    $bayonet->consult([
      'body' => [
        'transaction_id' => '<transaction ID that you used when reporting the transaction or solicitud>'
      ],
      'on_success' => function($response) {
        print_r($response);
      },
      'on_failure' => function($response) {
        print_r($response);
      }
    ]);
  • 反馈(就交易发送反馈 - 提出警报或阻止用户)

    $bayonet->feedback([
      'body' => [
        'transaction_id' => '<transaction ID that you used when reporting the transaction or solicitud>',
        'actions' => [
          'alert' => true,
          'block' => true
        ]
      ],
      'on_success' => function($response) {
        print_r($response);
      },
      'on_failure' => function($response) {
        print_r($response);
      }
    ]);
  • 历史反馈(报告未发送给Bayonet的历史交易)

    $bayonet->feedback_historical([
      'body' => [
        'email' => 'example@bayonet.io',
        'consumer_name' => 'Example name',
        'consumer_internal_id' => '<your internal ID for this consumer>',
        'telephone_fixed' => '1234567890',
        'telephone_mobile' => '1234567891',
        'telephone_reference_1' => '1234567892',
        'telephone_reference_2' => '1234567893',
        'telephone_reference_3' => '1234567894',
        'rfc' => 'Example RFC',
        'curp' => 'Example CURP',
        'clabe' => 'Example CLABE',
        'address' => [
          'line_1' => 'example line 1',
          'line_2' => 'example line 2',
          'city' => 'Mexico City',
          'state' => 'Mexico DF',
          'country' => 'MEX',
          'zip_code' => '64000'
        ],
        'bayonet_fingerprint_token' => '<token generated by Bayonet fingerprinting JS>',
        'transaction_category' => 'p2p_lending',
        'transaction_id' => '<your internal ID for this transaction>',
        'transaction_time' => 1476012879,
        'actions' => [
          'alert' => true,
          'block' => true
        ]
      ],
      'on_success' => function($response) {
        print_r($response);
      },
      'on_failure' => function($response) {
        print_r($response);
      }
    ]);

设备指纹

  • 初始化设备指纹客户端

    $bayonet = new Bayonet\DeviceFingerprintClient([
      'api_key' => 'your_api_key',
      'version' => 2
    ]);

    您还可以使用环境变量来加载API密钥

    export BAYONET_API_KEY=your_api_key
  • 获取指纹数据API您可以使用此端点获取由您前端上安装的Bayonet指纹JS生成的指纹的详细信息

    $bayonet->get_fingerprint_data([
        'body' => [
            'bayonet_fingerprint_token' => 'fingerprint-token-generated-by-JS-snipppet'
        ],
        'on_success' => function($response) {
            print_r($response);
        },
        'on_failure' => function($response) {
            print_r($response);
        }
    ]);

成功与错误处理

Bayonet的SDK支持成功和错误处理的回调函数

// make the request
$bayonet -> <EVENT>([
  'body' => ...,
  'on_success' => function($response) {
    print_r($response);
  },
  'on_failure' => function($response) {
    print_r($response);
  }
]);
?>

有关错误代码及其消息的完整列表,请参阅Bayonet的API文档

测试

您可以使用以下命令运行测试套件

./vendor/bin/phpunit tests