TiPayPal is a native Android module, which integrates the new [PayPal mobile SDK for Android] (https://github.com/paypal/PayPal-Android-SDK) in your Titanium Android app.
##Download
Grab the lastest build from the dist folder
Simply add the following lines to your tiapp.xml
file:
<modules>
<module platform="android">com.gbaldera.tipaypal</module>
</modules>
To access this module from JavaScript, you would do the following:
var tipaypal = require('com.gbaldera.tipaypal');
The TiPayPal variable is a reference to the Module object.
Mock environment. Pre-packaged fake transactions only. The SDK will not attempt to contact PayPal's servers with this environment.
####ENVIRONMENT_SANDBOX : String
Sandbox environment. Used for development & testing. Sandbox transactions can be seen in the dashboard.
####ENVIRONMENT_PRODUCTION : String
Live production environment. Real money will be moved in this environment.
List of methods supported in this module:
Initialize the SDK.
tipaypal.initialize({
environment: tipaypal.ENVIRONMENT_NO_NETWORK,
skip_credit_card: true,
client_id: "<YOUR_CLIENT_ID>",
receiver_email: "<YOUR_PAYPAL_EMAIL_ADDRESS>"
});
- environment [String]: Enviroment (one of the above)
- skip_credit_card [bool]: disable or enable credit card acceptance
- client_id [String]: Your client id Available on the PayPal developer site
- receiver_email [String]: The email address on the PayPal account used to obtain the above
client_id
Make a payment.
tipaypal.doPayment({
amount: "8.75",
currency: "USD",
description: "hipster jeans",
payer_id: "<someuser@somedomain.com>"
});
- amount [Number]: The payment amount
- currency [String]: Payment currency. For a complete list of supported currencies, read [here] (https://github.com/paypal/PayPal-Android-SDK#currencies)
- description [String]: Description of the payment
- payer_id [String]: Your customer ID. If you have a customer identifier that is not hardware- or device-based, such as an email address or a unique user ID in your system, you should provide it as a
payer_id
Fired when the payment was processed successfully.
- code : result code.
- confirmation : Payment confirmation. Send 'confirm' to your server for verification, [see here for more details] (https://developer.paypal.com/webapps/developer/docs/integration/mobile/verify-mobile-payment/)
var win = Ti.UI.createWindow({
backgroundColor:'white'
});
// TODO: write your module tests here
var tipaypal = require('com.gbaldera.tipaypal');
Ti.API.info("module is => " + JSON.stringify(tipaypal));
tipaypal.initialize({
environment: tipaypal.ENVIRONMENT_NO_NETWORK,
skip_credit_card: true,
client_id: "<YOUR_CLIENT_ID>",
receiver_email: "<YOUR_PAYPAL_EMAIL_ADDRESS>"
});
var buyItBtn = Ti.UI.createButton({
height:Ti.UI.SIZE,
width:Ti.UI.SIZE,
title:'Buy a thing'
});
win.add(buyItBtn);
var result_label = Ti.UI.createLabel({text: "", top: 20});
win.add(result_label);
buyItBtn.addEventListener("click", function(e){
tipaypal.doPayment({
amount: "8.75",
currency: "USD",
description: "hipster jeans",
payer_id: "<someuser@somedomain.com>"
});
});
tipaypal.addEventListener(tipaypal.EVENT_COMPLETED, function(e){
// TODO: send 'confirm' to your server for verification.
// see https://developer.paypal.com/webapps/developer/docs/integration/mobile/verify-mobile-payment/
// for more details.
result_label.text = JSON.stringify(e);
});
tipaypal.addEventListener(tipaypal.EVENT_ERROR, function(e){Ti.API.info(JSON.stringify(e));});
tipaypal.addEventListener(tipaypal.EVENT_CANCELLED, function(e){Ti.API.info(JSON.stringify(e));});
tipaypal.addEventListener(tipaypal.EVENT_PAYMENT_INVALID, function(e){Ti.API.info(JSON.stringify(e));});
win.open();
- 1.0: Initial version
Add the open source license acknowledgments from [acknowledgments.md] (https://github.com/paypal/PayPal-Android-SDK/blob/master/acknowledgments.md) to your app's acknowledgments.
Gustavo Rodriguez Baldera
It's open source and it's under DBAD License