Skip to content

Instantly share code, notes, and snippets.

@hansemannn
Created September 25, 2020 09:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hansemannn/6cb03dd1391e8878bc9981fce11068c0 to your computer and use it in GitHub Desktop.
Save hansemannn/6cb03dd1391e8878bc9981fce11068c0 to your computer and use it in GitHub Desktop.
Example of using the newest Stripe SDK for iOS/Android in Appcelerator Titanium (contact via @hans on TiSlack.org)
var Stripe = require('ti.stripe');
var win = Ti.UI.createWindow({
backgroundColor: '#fff',
layout: 'vertical'
});
win.addEventListener('open', initialize);
win.open();
addButton('Show payment options', showPaymentOptions);
addButton('Request payment', requestPayment);
function initialize() {
Stripe.initialize({
ephemeralKeyAPIURL: 'YOUR_EPHEMERAL_KEY_POST_API_URL',
publishableKey: 'YOUR_PUBLISHABLE_KEY',
companyName: 'YOUR_COMPANY_NAME',
styles: {
primaryBackgroundColor: 'white',
primaryForegroundColor: 'black',
secondaryForegroundColor: 'gray',
accentColor: 'blue'
}
});
updatePaymentDetails();
}
function updatePaymentDetails() {
Stripe.updatePaymentDetails({
currency: 'EUR',
country: 'DE',
items: [{
label: 'Einkauf für Hans',
amount: 12.50
}, {
label: 'Abwicklungsgebühr (1.9% + 0.25€',
amount: 0.49
}]
});
}
function showPaymentOptions() {
Stripe.showPaymentOptions();
}
function requestPayment() {
Stripe.requestPayment();
}
function addButton(title, action) {
var button = Ti.UI.createButton({ top: 75, title });
button.addEventListener('click', action);
win.add(button);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment