Copyright © 2017 Bambora Inc.
This repo contains a simple merchant Python/Flask server and associated Web and iOS clients to help process payments. The demo server & clients are intended to be simple examples that can help you with your production implementation.
Feel free to view and try out the Payment APIs Demo web app now!
The server project requires Python 3. To build & run the server for local dev you can use a SQLite DB and try the server out by just setting your Bambora Payments API Passcode as a server side environment variable and then start up as follows.
Clone the repo, and then do a:
make run
Server should now be running at http://127.0.0.1:8080.
- Execute a git clone command on this repo and in a terminal cd into the root project directory.
git clone https://github.com/bambora/na-payment-apis-demo.git
cd na-payment-apis-demo/server/app
- Install virtualenv (if not already available)
[sudo] pip install virtualenv
- Create (if not already created) and/or Activate project environment
virtualenv -p python3 venv
source venv/bin/activate
- Install/update project dependencies
cd server/app
pip install -r requirements.txt
We are using one test account on Production in this demo app. All services can be tested on Production.
export SERVER_URL_BASE="https://api.na.bambora.com" # Defaults to this and can be omitted
export DATABASE_URL=sqlite:////tmp/mobilepay-demo.db # Defaults to this and can be omitted
export MERCHANT_ID=<your_bambora_merchant_id>
export API_PASSCODE=<your_payment_api_passcode>
export BATCH_PAYMENT_API_PASSCODE=<your_batch_payment_api_passcode>
export REPORT_API_PASSCODE=<report_api_passcode>
(venv) app$ $env:SERVER_URL_BASE ="https://api.na.bambora.com" # Defaults to this and can be omitted
(venv) app$ $env:DATABASE_URL = "sqlite:////users/<your_user>/appdata/local/temp/mobilepay-demo.db"
(venv) app$ $env:MERCHANT_ID = "<your_bambora_merchant_id>"
(venv) app$ $env:API_PASSCODE = "<your_merchant_payments_passcode>"
From within the server/app directory:
python server.py
If you require HTTPS, then you'll need to create a local Certificate Authority (CA), trust it, and then generate certs to use.
Run the supplied gen-cert.sh
script. This creates the root CA & cert for the app.
sudo security add-trusted-cert -d -r trustAsRoot -k /Library/Keychains/System.keychain server/app/domain.crt
Once this is done, going to https://0.0.0.0:5000 should resolve without error.
Apple Pay or Android Pay payment requests are initiated from mobile clients and then, if successful, an Apple Pay or Android Pay token is transmitted to the demo payment server, which records the payment request and executes the Bambora Payments API.
In your production flow, a mobile client might transmit other info such as the customer identifier, detailed sales/inventory data, and related shipping and billing addresses. This info might be recorded on a merchant's CRM (as an example), and then a request to process the payment using the Apple Pay or Android Pay token would then be made to the Bambora Payments API. Upon success or failure to process the payment, the merchant's CRM could be updated and the originating mobile client would then receive a response.
The iOS client project was built with XCode 8 and requires Swift 3.0.
For details on how to develop Apple Pay enabled apps please visit:
When an Apple Pay client makes a payment request, it first gets an Apple Pay payment token using standard Apple SDK APIs. It then communicates this info to the Demo Server which is responsible for interacting with the Bambora Payments API. The Bambora Payments API has been updated to allow for Apple Pay transactions and the following is a sample POST parameter to use with a RESTful invocation of the Payments API.
payload = {
'amount': float(<purchase_amount>),
'payment_method': 'apple_pay',
'apple_pay': {
'apple_pay_merchant_id': <your_apple_pay_merchant_id>,
'payment_token': <apple_pay_base64_encoded_token>,
'complete': <true (Defaults to true if omitted. Used for a purchase) | false (Used for a Pre-Auth.)>
}
}
The Android client project was built with Android Studio v2.3.1.
For details on how to develop Android Pay enabled apps please visit:
https://developers.google.com/android-pay/
When an Android Pay client makes a payment request, it first gets an Android Pay payment token using standard Android SDK APIs. It then communicates this info to the Demo Server which is responsible for interacting with the Bambora Payments API. The Bambora Payments API has been updated to allow for Android Pay transactions and the following is a sample POST parameter to use with a RESTful invocation of the Payments API.
payload = {
'amount': float(<purchase_amount>),
'payment_method': 'android_pay',
'android_pay': {
'apple_pay_merchant_id': <your_android_pay_merchant_id>,
'payment_token': <apple_pay_base64_encoded_token>,
'complete': <true (Defaults to true if omitted. Used for a purchase) | false (Used for a Pre-Auth.)>
}
}
- Check out this repository
- Fork the repo to commit changes to and issue Pull Requests as needed.