FlexShopper API
3.0-legacy
FlexShopper API
3.0-legacy
  • Getting Started
  • Our Platforms
    • FlexPay Payment Platform
    • FlexShopper Backend API
  • API Reference
    • Get Started
      • API Requests
      • API Responses
      • Error Codes
    • User Management
      • Create User
      • Get Users
      • Get User
      • Verify User Exists
      • Deeply Verify User Exists
      • Get LoanPaymentPro Child Key
      • Add Payment Method
    • Customer Authentication
      • Request Passcode
      • Login Customer
    • Customer Application
      • Initiate Application
      • Get Verification Questions
      • Verify Answers
      • Validate Routing Number
    • Lease Management
      • Create Lease
      • Get Lease By ID
      • Sign Lease
      • Checkout
    • Purchase Transactions
      • Get Transactions
      • Get Transaction By ID
      • Cancel Items
      • Return Items
      • Confirm Shipment
      • Confirm Receipt
    • Products
      • Get Products
    • Settings
  • Change Log
Powered by GitBook
On this page
  • Preview the experience
  • Add the Payment Button to your store
  • Creating a transaction
  • Finalize the transaction
  • After the order has been placed
  • Congratulations!

Was this helpful?

Export as PDF
  1. Our Platforms

FlexPay Payment Platform

The FlexPay Payment Platform is a simple way to enable your users who may not otherwise qualify for financing to securely finance their order through our easy Lease to Own experience.

PreviousOur PlatformsNextFlexShopper Backend API

Last updated 10 months ago

Was this helpful?

Version 1 of the Payment Method is deprecated and will be shut off July 2020. If you're still on V1, please contact our integration team for assistance on migrating to V3.

How do you know if you're on V1? Check the domain you're directed to at check, if it's sdk.flexshopper.com, you're on V1.

Preview the experience

Add the Payment Button to your store

<script src="https://pp3.flexshopper.com/sdk/js?authKey=AUTH_KEY"></script>
<script>
FlexSDK.Button({
    createOrder: function() {}
    onSign: function() {}
}).render('#elementSelector');
</script>

Make sure to replace AUTH_KEY with your organization's assigned authorization key.

Creating a transaction

To create a lease, the createOrder method must be implemented. It will be called when the customer clicks on the FlexPay Payments button; once called, createOrder:

  • Launches the FlexShopper Payment modal where the customer may apply, get a spending limit, and sign the lease for their cart. Upon receiving a spending limit, customers are also given the chance to return to the store and add more items to their cart.

FlexSDK.Button({
    createOrder: function(data, actions) {
        return actions.transaction.create({
                cost: 120.34,
                transactionId: "ABC-129384",
                items: [
                    {
                        description: "Macbook Pro 13",
                        sku: "ABC123",
                        cost: 120.34,
                        brand: "Apple",
                        condition: "new",
                        quantity: 1,
                        images: [ // optional
                          "https://images.dog.ceo/breeds/husky/n02110185_11635.jpg" 
                        ],
                        shipping: {
                          cost: 10.33,
                          date: new Date(),
                          method: "UPS"
                        }
                    }
                ]
            });
    }
}).render('#elementSelector');

Finalize the transaction

Once the consumer has signed their lease, the onSign method will be called. In this method you are required to:

  • Retrieve the order from FlexShopper's system and validate the signed agreement.

  • Finalize the order, confirming the lease's total value and items, as well as confirming that the shipping process is underway.

If these steps are not followed, orders may not be fulfilled or billed correctly. You will have to implement an endpoint that your customers can interact with that consumes our Backend API:

On the client:

FlexSDK.Button({
    onSign: function(data) {
        return fetch('/validate-order', {
            method: 'POST',
            body: JSON.stringify(data)
        })
    }
}).render('#elementSelector');

The data object will have the following shape:

{
    "leaseNumber": "1234567",
    "transactionId": "ABC-129384"
}

On the server:

const axios = require('axios');
// helper method holding business logic to validate order
const checkOrder = require('utils/check-order.js');

const flexShopperClient = axios.create({
 baseURL: 'https://apis.sandbox.flexshopper.com/v3',
 headers: {
  Authorization: 'YOUR_API_KEY'
 }
});

 export const validateOrderHandler = async (req, res) => {
  const transactionId = req.body.transactionId;
  const transaction = await flexShopperClient.get(`/transactions/${transactionId}`)
  const orderStatus = await checkOrder(transaction)
  
  if (!orderStatus.isValid) {
   res.json({valid: false, errors: orderStatus.errors});
   return res.send(400);
  }
  
  await flexShopperClient.post(`/transactions/${transactionId}/finalize`)
  
  res.json({valid: true});
  res.send(200);
 }; 
use GuzzleHttp\Client;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Message\ResponseInterface;
use Zend\Diactoros\Response\JsonResponse;

$app->post('/validate-order', function (ServerRequestInterface $request): ResponseInterface {
    $flexShopperClient = new Client([
        'base_uri' => 'https://apis.sandbox.flexshopper.com/v3',
        'headers' => [
            'Authorization' => 'YOUR_API_KEY'
        ]
    ]);

    $transactionId = $request->getParsedBody()['transactionId'];
    $transaction = json_decode($flexShopperClient->get("/transactions/${transactionId}")->getBody());
    $orderStatus = $checkOrder($transaction);

    if (!$orderStatus->isValid) {
        return new JsonResponse(['valid' => false, 'errors' => $orderStatus->errors], 400);
    }
    
    $flexShopperClient->post("/transactions/${transactionId}/finalize");

    return new JsonResponse(['valid' => true, 'parsed_body' => $transactionId]);
});

from flask import Flask
from flask import jsonify
from flask import request
from requests_toolbelt import sessions

app = Flask(__name__)


flexshopper_client = sessions.BaseUrlSession(base_url='https://apis.sandbox.flexshopper.com/v3')
flexshopper_client.headers.update({'Authorization': 'YOUR_API_KEY'})


@app.route('/validate-order', methods=['POST'])
def validate_order():
    data = request.get_json()
    transaction_id = data['transactionId']
    transaction = flexshopper_client.get('/transaction/%s' % transaction_id)
    order_status = check_order(transaction)

    if not order_status['valid']:
        return jsonify({'valid': False, 'errors': order_status['errors']}), 400, {'ContentType': 'application/json'}

    flexshopper_client.post('/transaction/%s/finalize' % transaction_id)
    return jsonify({'valid': True}), 200

Make sure to replace API_KEY with your organization's assigned API key. Note that API keys and authorization keys are separate.

Endpoints

After the order has been placed

Once FlexShopper receives confirmation that the consumer has received their item (delivery confirmation), your organization will be paid for the value of the lease. Use the Confirm Shipment API endpoint to inform FlexShopper of the shipment's status:

Congratulations!

Once you've confirmed shipment, you're done. That's all there is to it!

Makes use of actions.transaction.create() to create a valid order. A complete list of options can be found .

Checkout
Get Transaction By ID
Confirm Shipment
here