bsecure/bsecure-laravel

巴基斯坦首个适用于电子商务商店的通用结账解决方案,基于woocommerce、magento、shopify等构建

1.0.5 2021-04-06 11:18 UTC

This package is auto-updated.

Last update: 2024-09-04 15:55:20 UTC


README

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

bSecure Checkout

巴基斯坦首个易于集成在您的电子商务商店中的通用结账解决方案。

bSecure Checkout 简介

它为您提供了启用 通用登录两步结账、接受多种支付方式以及无烦恼地运行您的电子商务商店的选项。
它适用于 桌面平板电脑移动设备,并且持续进行测试和更新,以为您提供无缝的支付体验。

安装

您可以通过 composer 安装此软件包

composer require bSecure/bsecure-laravel

先决条件

PHP 7.2.5 及以上版本

依赖关系

"guzzlehttp/guzzle": "^7.2"

使用方法

配置设置

通过遵循几个简单的步骤,您可以设置您的 bSecure Checkout单一登录

获取凭证

  1. 前往 合作伙伴门户
  2. 应用程序集成 >> 沙盒 / 实时
  3. 选择环境类型(自定义集成)
  4. 填写以下字段
    a. 商店 URL 在任何情况下都需要
    b. 登录重定向 URL 需要用于功能 使用 bSecure 登录
    c. 结账重定向 URL 需要用于功能 使用 bSecure 支付
    d. 结账订单状态 webhook 需要用于功能 使用 bSecure 支付
  5. 保存您的客户端凭证(客户端 ID 和客户端密钥)
  6. 请确保在代码中安全地保存凭证

bSecure Checkout

在 app.php 中添加 bSecure checkout 提供商

bSecure\UniversalCheckout\CheckoutServiceProvider::class

添加别名

'BsecureCheckout' => bSecure\UniversalCheckout\BsecureCheckout::class

发布语言文件。

php artisan vendor:publish --provider="bSecure\UniversalCheckout\CheckoutServiceProvider"

它将在 resources/lang 文件夹内创建一个 vendor/bSecure 文件夹。如果您想自定义错误消息,可以覆盖该文件。

发布配置文件

php artisan vendor:publish --provider="bSecure\UniversalCheckout\CheckoutServiceProvider" --tag="config"

将在 config 文件夹中放置一个文件(bSecure.php)。

return [
  'client_id' => env('BSECURE_CLIENT_ID', ''),
  'client_secret' => env('BSECURE_CLIENT_SECRET',''),

  'environment' => env('BSECURE_ENVIRONMENT'),
];

示例

创建订单

要创建订单,您应该有一个 order_id、customer 和 products 对象参数,这些参数在创建订单之前需要设置。

创建订单请求参数
产品对象

Products 对象应采用以下格式

"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"
  }
]
产品选项对象

Products 对象应采用以下格式

'product_options' =>  
    array (
      0 => array (
              'id' => 'option-id(numeric)',
              'name' => 'option-name',
              'value' => array (
                0 => array (
                        'name' => 'option-value-name',
                        'price' => 'option-value-price',
                     ),   
              ),
           ),   
    ),
运输对象

运输对象应采用以下格式

1- 如果商家想要他的预指定运输方式,则应按以下格式传递运输方式详情

"shipment": {
  "charges": "numeric",
  "method_name": "string"
}
客户对象

客户对象应采用以下格式

1- 如果客户已经通过 bSecure 在您的系统中登录,并且您有客户的 auth-code,则只需在客户对象中传递该代码,无需传递其余字段。

2- 由于客户对象中的所有字段都是可选的,如果没有关于客户的任何信息,则只需传递空对象,或者如果有客户详细信息,则您的客户对象应采用以下格式

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

创建订单

use bSecure\UniversalCheckout\BsecureCheckout;
$order = new BsecureCheckout();

$order->setOrderId($orderId);
$order->setCustomer($customer);
$order->setCartItems($products);
$order->setShipmentDetails($shipment);

$result =  $order->createOrder();
return $result;

响应createOrder()函数,将返回订单过期时间、结账URL、订单参考号和商户订单ID。

array (
  'expiry' => '2020-11-27 10:55:14',
  'checkout_url' => 'bSecure-checkout-url',
  'order_reference' => 'bsecure-reference',
  'merchant_order_id' => 'your-order-id',
) 

如果您使用的是Web解决方案,则只需将用户重定向到结账URL。

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

如果您有Android或IOS SDK,则初始化您的SDK并向其中提供订单参考号。

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

当在bSecure上成功创建订单时,您将被重定向到bSecure SDK或bSecure结账应用,在那里您将处理结账。

订单放置回调

一旦订单成功提交,bSecure将把客户重定向到您在合作伙伴门户的“结账重定向URL”中提到的URL,并在查询字符串中添加一个额外的参数“order_ref”。

订单更新

您可以通过在“订单放置回调”中收到的order_ref调用以下方法来获取订单详情。

use bSecure\UniversalCheckout\BsecureCheckout;
$order_ref = $order->order_ref;

$orderStatusUpdate = new BsecureCheckout();
$result =  $orderStatusUpdate->orderStatusUpdates($order_ref);
return $result;

订单状态变更Webhook

无论订单状态或支付状态发生任何变化,bSecure都会将完整的订单详情(内容将与订单更新的响应相同)发送到您在合作伙伴门户的环境设置中提到的“结账订单状态Webhook”URL。您的Webhook必须能够接受POST请求。

在“订单放置回调”和“订单更新”的响应中,您将以以下所述格式接收到您订单的完整详情。

{
  "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
}

管理订单和支付

支付状态

订单状态

bSecure单点登录(SSO)

在app.php中添加bSecure结账和单点登录的提供者

bSecure\UniversalCheckout\SSOServiceProvider::class

添加别名

'BsecureSSO' => bSecure\UniversalCheckout\BsecureSSO::class

发布语言文件。

php artisan vendor:publish --provider="bSecure\UniversalCheckout\SSOServiceProvider"

它将在 resources/lang 文件夹内创建一个 vendor/bSecure 文件夹。如果您想自定义错误消息,可以覆盖该文件。

发布配置文件

php artisan vendor:publish --provider="bSecure\UniversalCheckout\SSOServiceProvider" --tag="config"

将在 config 文件夹中放置一个文件(bSecure.php)。

在使用bSecure SSO之前,您还需要添加应用程序使用的OAuth服务的凭据。这些凭据应放置在config/bSecure.php配置文件中。例如


return [
  'client_id' => env('BSECURE_CLIENT_ID', ''),
  'client_secret' => env('BSECURE_CLIENT_SECRET',''),

  'environment' => env('BSECURE_ENVIRONMENT'),
];

路由

接下来,您已准备好验证用户!您需要两个路由:一个用于将用户重定向到OAuth提供者,另一个用于在验证后从提供者接收客户资料。我们将使用BsecureSSO Facade来访问BsecureSSO。

验证客户端

客户端验证有两种类型:SDK和Web客户端验证。

如果您使用的是Web解决方案,则使用以下方法

use bSecure\UniversalCheckout\BsecureSSO;

$state = $requestData['state'];

$client = new BsecureSSO();
return $client->authenticateWebClient($state);

响应中,authenticateWebClient将返回redirect_url,然后简单地将用户重定向到redirect_url。

array (
  "redirect_url": "your-authentication-url"

)

如果您使用的是SDK解决方案,则使用以下方法

use bSecure\UniversalCheckout\BsecureSSO;

$state = $requestData['state'];

$client = new BsecureSSO();
return $client->authenticateSDKClient($state);

响应中,authenticateSDKClient将返回request_id、merchant_name和store_url,您必须将其传递给您的SDK。

array (
  "request_id": "your-request-identifier",
  "merchant_name": "builder-company-name",
  "store_url": "builder-store-url"
)

客户端授权

授权成功后,
bSecure将重定向到您在合作伙伴门户设置环境时提供的登录重定向URL,并在查询字符串中包含两个参数:codestate

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

在上面的回调中收到的code是客户的auth_code,将用于获取客户资料。

验证回调

通过将您在回调中收到的state与在发送客户端验证请求之前存储在数据库中的值进行比较来验证您收到的state,只有当这两个值匹配时,您才应继续进行。

获取客户资料

客户端授权收到的auth_code应传递到以下方法以获取客户资料。

use bSecure\UniversalCheckout\BsecureSSO;

$auth_code = $requestData['auth_code'];

$client = new BsecureSSO();
return $client->customerProfile($auth_code);

响应中,它将返回客户姓名、电子邮件、电话号码、国家代码和地址簿。

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' => '',
        ),
)

变更日志

请参阅变更日志获取更多关于最近更改的信息。

许可协议

MIT 许可协议(MIT)。有关更多信息,请参阅许可文件

贡献

"bSecure – 您的通用结账系统"是开源软件。