Stripe Integration plugin enables secure processing of credit card transactions using Stripe. Additionally, the plugin can update the app about the status of the transaction, which is handled through an asynchronous callback.
Stripe Integration plugin enables secure processing of credit card transactions using Stripe. Additionally, the plugin can update the app about the status of the transaction, which is handled through an asynchronous callback.
The product integrates the Stripe service with Backendless to enable secure credit card processing and transaction status notification. Using Stripe Integration plugin developers can enjoy the simplicity of transaction processing by Stripe with the security and reliability of the Backendless servers. With the power of real-time messaging and real-time database, Backendless apps instantly get a notification when Stripe finishes transaction processing so the end user can be notified without waiting.
The Stripe integration plugin enables server-side validation and callback handling for payments processed by Stripe. The overall flow of the Backendless/Stripe integration can be seen in the diagram below:
POST /Stripe/charge
route.StripeEvents
table). Additionally, Backendless publishes the information into a messaging channel. The client app can subscribe to an event using Backendless Real-Time Messaging (channel: stripe/<transaction-id>
). When it receives a message with the transaction status, the app can inform the user that the transaction has been completed.There are a few things to note:
https://<APP-CUSTOM-DOMAIN>/api/services/Stripe/webhooks/handler
<APP-CUSTOM-DOMAIN>
is one of your Backendless application custom domains.When a webhook is registered with Stripe, the Stripe Integration plugin processes Stripe events and performs the following actions:
Events in the database are stored in the StripeEvents
table. The table has the following schema (you do not need to create it manually unless the Dynamic Schema Definition option is disabled):
where:
id
column contains the id of the transaction.type
column contains the event type.The screenshot below shows sample contents of the data table:
Additionally, the plugin implementation sends out the payload of the event through Backendless Real-Time Messaging. To receive the messages, the client application must subscribe to the stripe
messaging channel. To receive a message for a specific transaction, the following selector must be used:
id = 'transaction id'
For example,
id = 'ch_1Cmms9I56A1133zjexAcwndb'
The transaction id
can be obtained from the response object received for the “Initiating a charge” API call documented below.
The Stripe Integration plugin provides the following APIs:
This is the API which is used in step 3 in the diagram above:
Backendless.initApp( "YOUR-APP-ID", "ANDROID-API-KEY" );
float amount = AMOUNT-TO-CHARGE;
HashMap<String, Object> params = new HashMap<String,Object>();
params.put( "token", TOKEN-VALUE-FROM-STRIPE );
params.put( "amount", amount );
Object[] args = new Object[]{ params };
Backendless.CustomService.invoke( "Stripe", "charge", args, Object.class,
new AsyncCallback<Object>()
{
@java.lang.Override
public void handleResponse( Object response )
{
Log.info( "MYAPP", "Charge has been submitted" );
// to get a real-time message:
HashMap responseHash = (HashMap) response;
String txId = (String) responseHash.get("id");
Channel channel = Backendless.Messaging.subscribe("stripe");
channel.addMessageListener("id = '" + txId + "'", new AsyncCallback<HashMap>() {
@Override
public void handleResponse(HashMap response) {
Log.i( "MYAPP", "got webhook callback " + response );
}
@Override
public void handleFault(BackendlessFault fault) {
Log.e( "MYAPP", "got error " + fault.toString() );
}
}, HashMap.class );}
@java.lang.Override
public void handleFault( BackendlessFault fault )
{
Log.error( "MYAPP", "Server returned an error " + fault );
}
});
Backendless.initApp( YOUR-APP-ID, YOUR-JS-API-KEY );
var chargeData = {
token: TOKEN-VALUE-FROM-STRIPE,
amount: AMOUNT-TO-CHARGE
}
Backendless.CustomServices.invokeSync( "Stripe", "charge", [ chargeData ] )
.then( function( result ) {
// result.id provides transaction id
})
.catch( function( error ) {
});
curl -X "POST" "https://api.backendless.com/<API-ID>/<API-KEY>/services/Stripe/charge" \
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
-d $'{
"amount" : <amount>,
"token" : <token>
}'