Created
September 25, 2020 09:24
-
-
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)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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