承接 bsecure/bsecure-php 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

bsecure/bsecure-php

Composer 安装命令:

composer require bsecure/bsecure-php

包简介

PHP library for the bSecure.

README 文档

README

Latest Version on Packagist Latest Stable Version Total Downloads License Build Status Code Coverage Scrutinizer Code Quality

bSecure

bSecure is a utility library for two-click checkout custom integration. bSecure library simplifies communication between builder and bSecure server and processing tasks for builder's ease.

About bSecure Checkout

It gives you an option to enable universal-login, two-click checkout and accept multiple payment method for your customers, as well as run your e-commerce store hassle free.
It is built for desktop, tablet, and mobile devices and is continuously tested and updated to offer a frictionless payment experience for your e-commerce store.

Manual Installation

To use the bindings, include the init.php file.

require_once('/path/to/bSecure-php/init.php')

Prerequisites

The bindings require the following extensions in order to work properly:

  • curl

If you want to install the package manually, you'll have to make sure that these extensions are available.

Documentation

Visit our Site bSecure to read the documentation and get support.

Configuration Setup

By following a few simple steps, you can set up your bSecure Checkout and Single-Sign-On.

Getting Your Credentials

  1. Go to Builder's Portal
  2. App Integration >> Sandbox / Live
  3. Select Environment Type (Custom Integration)
  4. Fill following fields:
    a. Store URL its required in any case
    b. Login Redirect URL Required for feature Login with bSecure
    c. Checkout Redirect URL Required for feature Pay with bSecure
    d. Checkout Order Status webhook Required for feature Pay with bSecure
  5. Save your client credentials (' and ')
  6. Please make sure to keep credentials at safe place in your code.

Client Authentication

To call below mentioned functions of bSecure, you first have to authenticate your client. Following function will be used to authenticate your client:

\bSecure\bSecure::setClientId('<YOUR-CLIENT-ID>');
\bSecure\bSecure::setClientSecret('<YOUR-CLIENT-SECRET>');
\bSecure\bSecure::setAppEnvironment('<YOUR-APP-ENVIRONMENT>');
\bSecure\bSecure::getAuthToken();

<YOUR-CLIENT-ID> and <YOUR-CLIENT-SECRET> can be obtained from Builder's Portal for your application.

We suggest to call this function before each of the following to keep authentication updated:

  • create_order
  • order_status
  • get_customer_profile

bSecure Checkout

Create Order

To create an order you should have an order_id, customer, charges and products object parameters that are to be set before creating an order.

Create Order Request Params:
Product Object:

Products object should be in below mentioned format:

"products": [
  {
  "id": "product-id",
  "name": "product-name",
  "sku": "product-sku",
  "quantity": 0,
  "price": 0,
  "sale_price": 0,
  "image": "product-image",
  "description": "product-description",
  "short_description": "product-short-description"
  }
]
Shipment Object

Shipment object should be in below mentioned format:

1- If the merchant want his pre-specified shipment method then he should pass shipment method detail in below mentioned format:

"shipment": {
  "charges": "numeric",
  "method_name": "string"
}
Customer Object

Customer object should be in below mentioned format:

1- If the customer has already signed-in via bSecure into your system and you have auth-code for the customer you can just pass that code in the customer object no need for the rest of the fields.

2- Since all the fields in Customer object are optional, if you don’t have any information about customer just pass the empty object, or if you have customer details then your customer object should be in below mentioned format:

"customer": {
  "name": "string",
  "email": "string",
  "country_code": "string",
  "phone_number": "string",
}
Charges Object

Charges object should be in below mentioned format:

"order_charge" : {
  "sub_total" : "float",
  "discount" : "float",
  "total" : "float",
}

Create Order

\bSecure\Order::setOrderId('<YOUR-ORDER-ID>');
\bSecure\Order::setCustomer($customer);
\bSecure\Order::setShipmentDetails($shipment);
\bSecure\Order::setCartItems($products);
\bSecure\Order::setCharges($charges);
$result = \bSecure\Order::createOrder();
return $result;

In response createOrder(), will return order expiry, checkout_url, order_reference and merchant_order_id.

array (
  'expiry' => '2020-11-27 10:55:14',
  'checkout_url' => 'bSecure-checkout-url',
  'store_url' => 'store-url',
  'order_reference' => 'bsecure-reference',
  'merchant_order_id' => '<YOUR-ORDER-ID>',
) 

If you are using a web-solution then simply redirect the user to checkout_url

if(!empty($result['checkout_url']))
return redirect($result['checkout_url']); 

When order is created successfully on bSecure, you will be redirected to bSecure checkout app where you will process your checkout.

If you have Android or IOS SDK then initialize your sdk and provide order_reference,checkout_url and store_url to it

if(!empty($result']))
return $result; 

Callback on Order Placement

Once the order is successfully placed, bSecure will redirect the customer to the url you mentioned in “Checkout redirect url” in your environment settings in Builder's Portal, with one additional param order_ref in the query string.

Order Updates

By using order_ref you received in the "Callback on Order Placement" you can call below method to get order details.

$order_ref = $order->order_ref;

$result =  \bSecure\Order::orderStatus($order_ref);
return $result;

Order Status Change Webhook

Whenever there is any change in order status or payment status, bSecure will send you an update with complete order details (contents will be the same as response of Order Updates on the URL you mentioned in Checkout Order Status webhook in your environment settings in Builder's Portal. (your webhook must be able to accept POST request).

In response of "Callback on Order Placement" and "Order Updates" you will recieve complete details of your order in below mentioned format:

{
  "status": 200,
  "message": [
    "Request Successful"
  ],
  "body": {
    "merchant_order_id": "your-order-id",
    "order_ref": "bsecure-order-reference",
    "order_type": "App/Manual/Payment gateway",
    "placement_status": "6",
    "payment_status": null,
    "customer": {
      "name": "",
      "email": "",
      "country_code": "",
      "phone_number": "",
      "gender": "",
      "dob": ""
    },
    "payment_method": {
      "id": 5,
      "name": "Debit/Credit Card"
    },
    "card_details": {
      "card_type": null,
      "card_number": null,
      "card_expire": null,
      "card_name": null
    },
    "delivery_address": {
      "country": "",
      "province": "",
      "city": "",
      "area": "",
      "address": "",
      "lat": "",
      "long": ""
    },
    "shipment_method": {
      "id": 0,
      "name": "",
      "description": "",
      "cost": 0
    },
    "items": [
      {
        "product_id": "",
        "product_name": "",
        "product_sku": "",
        "product_qty": ""
      },
    ],
    "created_at": "",
    "time_zone": "",
    "summary": {
      "total_amount": "",
      "sub_total_amount": "",
      "discount_amount": "",
      "shipment_cost": "",
      "merchant_service_charges": ""
    }
  },
  "exception": null
}

Managing Orders and Payments

Payment Status

ID Value Description
0 Pending Order received, no payment initiated.Awaiting payment (unpaid).
1 Completed Order fulfilled and complete. Payment also recieved.
2 Failed Payment failed or was declined (unpaid) or requires authentication.

Order Status

ID Value Description
1 Created A customer created an order but not landed on bsecure
2 Initiated Order is awaiting fulfillment.
3 Placed Order fulfilled and complete Payment received. Order is awaiting fulfillment. – requires no further action
4 Awaiting Confirmation Awaiting action by the customer to authenticate the transaction.
5 Canceled Canceled by an admin or the customer.
6 Expired Orders that were not fulfilled within a pre-specified timeframe. timeframe
7 Failed Payment failed or was declined (unpaid).Note that this status may not show immediately and instead show as Pending until verified
8 Awaiting Payment Order received, no payment initiated. Awaiting payment (unpaid)

bSecure Single Sign On (SSO)

Authenticate Client

You can authenticate your client by calling below mentioned function

Save the provided state as you will receive the same state in the successful authorization callback.

$client = bSecure\SSO::clientAuthenticate($state);
return redirect($client['redirect_url']); 

In response clientAuthenticate(), will return a redirect_url, on which you have to redirect your customer.

array (
  "redirect_url": "<SSO-REDIRECT-LINK>",
)

Client Authorization

On Successful Authorization,
bSecure will redirect to you provided when setting up environment in Builders portal, along with two parameters in query string: code and state

eg: https://my-store.com/sso-callback?code=abc&state=xyz

code received in above callback is customer's auth_code which will be further used to get customer profile.

Verify Callback

Verify the state you received in the callback by matching it to the value you stored in DB before sending the client authentication request, you should only proceed if and only if both values match.

Get Customer Profile

Auth_code recieved from Client Authorization should be passed to method below to get customer profile.

return bSecure\SSO::customerProfile('<AUTH-CODE>');

In response, it will return customer name, email, phone_number, country_code, address book.

array (
    'name' => 'customer-name',
    'email' => 'customer-email',
    'phone_number' => 'customer-phone-number',
    'country_code' => customer-phone-code,
    'address' => 
        array (
          'country' => '',
          'state' => '',
          'city' => '',
          'area' => '',
          'address' => '',
          'postal_code' => '',
        ),
)

Changelog

Please see CHANGELOG for more information what has changed recently.

License

The MIT License (MIT). Please see License File for more information.

Contributions

"bSecure – Your Universal Checkout" is open source software.

bsecure/bsecure-php 适用场景与选型建议

bsecure/bsecure-php 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 13 次下载、GitHub Stars 达 0, 最近一次更新时间为 2021 年 02 月 04 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「ecommerce」 「SSO」 「e-commerce」 「single-sign-on」 「payment-gateway」 「bsecure」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 bsecure/bsecure-php 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 bsecure/bsecure-php 我们能提供哪些服务?
定制开发 / 二次开发

基于 bsecure/bsecure-php 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 13
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 9
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-02-04