PHPackages                             bsecure/bsecure-php - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Authentication &amp; Authorization](/categories/authentication)
4. /
5. bsecure/bsecure-php

ActiveLibrary[Authentication &amp; Authorization](/categories/authentication)

bsecure/bsecure-php
===================

PHP library for the bSecure.

1.0.3(5y ago)0131MITPHPPHP &gt;=5.6.0

Since Mar 5Pushed 5y agoCompare

[ Source](https://github.com/bSecureCheckout/bsecure-php)[ Packagist](https://packagist.org/packages/bsecure/bsecure-php)[ Docs](https://github.com/bSecureCheckout/bsecure-php)[ RSS](/packages/bsecure-bsecure-php/feed)WikiDiscussions master Synced 1w ago

READMEChangelog (4)DependenciesVersions (5)Used By (0)

 [![](https://camo.githubusercontent.com/b1bb89397070b6dc3deb37fba737ed350f9ef527436429074e8f2925271328dc/68747470733a2f2f627365637572652d6465762e73332d65752d776573742d312e616d617a6f6e6177732e636f6d2f6465762f72656163745f6170702f6173736574732f7365637572655f6c6f676f2e706e67)](https://camo.githubusercontent.com/b1bb89397070b6dc3deb37fba737ed350f9ef527436429074e8f2925271328dc/68747470733a2f2f627365637572652d6465762e73332d65752d776573742d312e616d617a6f6e6177732e636f6d2f6465762f72656163745f6170702f6173736574732f7365637572655f6c6f676f2e706e67)

[![Latest Version on Packagist](https://camo.githubusercontent.com/8399293c2748e1ba01761e3d710fbb12d8cdbb92bf3c429051c03ab487d0a4be/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f627365637572652f627365637572652d7068702e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/bsecure/bsecure-php)[![Latest Stable Version](https://camo.githubusercontent.com/c3a7831fbe6cd141bca60007f3f5d89f2e5dec8e92459e35b4280b5bcf916185/68747470733a2f2f706f7365722e707567782e6f72672f627365637572652f627365637572652d7068702f76)](https://packagist.org/packages/bsecure/bsecure-php)[![Total Downloads](https://camo.githubusercontent.com/4a667740b72dc7610e6330b486c5a5a1aa3a1460f71e1f6332e9bbf8e3fb4d3c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f627365637572652f627365637572652d7068702e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/bsecure/bsecure-php)[![License](https://camo.githubusercontent.com/cbdb26b16f12240de45cce2c7797b83ee708635239f38219ed273ead05667558/68747470733a2f2f706f7365722e707567782e6f72672f627365637572652f627365637572652d7068702f6c6963656e7365)](//packagist.org/packages/bsecure/bsecure-php)[![Build Status](https://camo.githubusercontent.com/475a6072164e4b959c9aba579e09d55431b375dbfe108df8c2df17fdd0013c54/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f62536563757265436865636b6f75742f627365637572652d7068702f6261646765732f6275696c642e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/bSecureCheckout/bsecure-php/build-status/master)[![Code Coverage](https://camo.githubusercontent.com/453ffeff9d6656dc36deb2c8d32ed190ffba5a58d68016afa7ba419f32a352f0/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f62536563757265436865636b6f75742f627365637572652d7068702f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/bSecureCheckout/bsecure-php/?branch=master)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/2c99a0362bf15d335394ae43f94bac00e9d4e1a72ca7a0fb0cac9dde896933ee/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f62536563757265436865636b6f75742f627365637572652d7068702f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/bSecureCheckout/bsecure-php/?branch=master)

bSecure
=======

[](#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

[](#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

[](#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

[](#documentation)

Visit our Site [bSecure](https://www.bsecure.pk/) to read the documentation and get support.

### Configuration Setup

[](#configuration-setup)

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

#### Getting Your Credentials

[](#getting-your-credentials)

1. Go to [Builder's Portal](https://builder.bsecure.pk/)
2. [App Integration](https://builder.bsecure.pk/integration-sandbox) &gt;&gt; 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
---------------------

[](#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('');
\bSecure\bSecure::setClientSecret('');
\bSecure\bSecure::setAppEnvironment('');
\bSecure\bSecure::getAuthToken();
```

` and  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
----------------

[](#bsecure-checkout)

#### Create Order

[](#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:

[](#create-order-request-params)

###### Product Object:

[](#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)

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)

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)

Charges object should be in below mentioned format:

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

```

#### Create Order

[](#create-order-1)

```
\bSecure\Order::setOrderId('');
\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' => '',
)

```

> 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

[](#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](https://builder.bsecure.pk/) in [Builder's Portal](https://builder.bsecure.pk/), with one additional param **order\_ref** in the query string.

#### Order Updates

[](#order-updates)

By using order\_ref you received in the "**[Callback on Order Placement](#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

[](#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](#order-updates)* on the URL you mentioned in *Checkout Order Status webhook* in your environment settings in [Builder's Portal](https://builder.bsecure.pk/). (your webhook must be able to accept POST request).

In response of "**[Callback on Order Placement](#callback-on-order-placement)**" and "**[Order Updates](#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

[](#managing-orders-and-payments)

#### Payment Status

[](#payment-status)

IDValueDescription0PendingOrder received, no payment initiated.Awaiting payment (unpaid).1CompletedOrder fulfilled and complete. Payment also recieved.2FailedPayment failed or was declined (unpaid) or requires authentication.#### Order Status

[](#order-status)

IDValueDescription1CreatedA customer created an order but not landed on bsecure2InitiatedOrder is awaiting fulfillment.3PlacedOrder fulfilled and complete Payment received. Order is awaiting fulfillment. – requires no further action4Awaiting ConfirmationAwaiting action by the customer to authenticate the transaction.5CanceledCanceled by an admin or the customer.6ExpiredOrders that were not fulfilled within a pre-specified timeframe. timeframe7FailedPayment failed or was declined (unpaid).Note that this status may not show immediately and instead show as Pending until verified8Awaiting PaymentOrder received, no payment initiated. Awaiting payment (unpaid)bSecure Single Sign On (SSO)
----------------------------

[](#bsecure-single-sign-on-sso)

### Authenticate Client

[](#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": "",
)

```

### Client Authorization

[](#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-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

[](#get-customer-profile)

Auth\_code recieved from **[Client Authorization](#client-authorization)** should be passed to method below to get customer profile.

```
return bSecure\SSO::customerProfile('');
```

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

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.

License
-------

[](#license)

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

Contributions
-------------

[](#contributions)

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

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity51

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

4

Last Release

1900d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/643da019ee59d48b5bdd5f319da813a392ca46c9cd6e7cf540a92aaf161fcbe4?d=identicon)[bSecure](/maintainers/bSecure)

---

Top Contributors

[![SaraHasan224](https://avatars.githubusercontent.com/u/38839068?v=4)](https://github.com/SaraHasan224 "SaraHasan224 (12 commits)")

---

Tags

universal-checkout-for-pakistanSSOsingle sign onecommercee-commercepayment gatewaybsecureuniversal-checkouttwo-step-checkoutuniversal-loginfrictionless payment

### Embed Badge

![Health badge](/badges/bsecure-bsecure-php/health.svg)

```
[![Health](https://phpackages.com/badges/bsecure-bsecure-php/health.svg)](https://phpackages.com/packages/bsecure-bsecure-php)
```

###  Alternatives

[league/oauth2-client

OAuth 2.0 Client Library

3.8k118.6M1.2k](/packages/league-oauth2-client)[league/oauth1-client

OAuth 1.0 Client Library

99898.8M106](/packages/league-oauth1-client)[humanmade/wp-simple-saml

WordPress Simple SAML plugin

124284.7k2](/packages/humanmade-wp-simple-saml)[adam-paterson/oauth2-stripe

Stripe OAuth 2.0 Client Provider for The PHP League OAuth2-Client

172.4M4](/packages/adam-paterson-oauth2-stripe)[adam-paterson/oauth2-slack

Slack OAuth 2.0 Client Provider for The PHP League OAuth2-Client

22694.8k5](/packages/adam-paterson-oauth2-slack)[ecphp/cas-bundle

A bundle for Symfony, providing authentication against a Central Authentication Service (CAS) server.

48132.1k1](/packages/ecphp-cas-bundle)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
