I would like to use the paypal sideloader api to integrate PayPal Here as described here: https://github.com/paypal/here-sideloader-api-samples/blob/master/docs/README.md
There are several things I am not sure how it works. Can someone help me understand it/point me in the right direct?
To launch the PayPal Here, you use the following url:
paypalhere://takePayment?
accepted=cash,card,paypal
&returnUrl=my_registered_location://takePayment/{result}?Type={Type}&InvoiceId={InvoiceId}&Tip={Tip}&TxId={TxId}
&as=b64
&step=choosePayment
&payerPhone=4155551212
&invoice={ ... json snipped ... }
How exactly do "open" this paypalhere://
schema? I would ideally like to have a button on my view called Pay via PayPal Here and when clicked, execute the above.
Secondly, notice how there is a returnUrl
? This is a custom url schema for my app. Firstly, how do I register my own url schema (e.g. myapp://
) and then implement the method takePayment
to get the payment response data?
Thanks in advance for any help & tips.
Yes, you are correct, add a button and call a function like
function handlePaypal(){
if (Ti.Platform.canOpenURL("paypalhere://")) {
Ti.Platform.openURL("paypalhere://"+ yourstring);
}
...
}
However you need to add this schema to your tiapp.xml file
<ios>
<plist>
<dict>
<.....>
<key>LSApplicationQueriesSchemes</key>
<array>
<string>paypalhere</string>
</array>
<....>
</dict>
</plist>
</ios>
EDITED
To handle de URL response, you will need to handle the open event as following:
If your App is designed for Android also, you will need to read the receiving intent data like below, as you are using Alloy, you need to put at app/alloy.js
if (OS_ANDROID) {
Alloy.Globals.receivedURL = Ti.Android.currentActivity.intent.data;
}
And finally at the beginning of your index.js
$.index.addEventListener('open', function (e) {
if (OS_ANDROID) {
handleResponse(Alloy.Globals.receivedURL);
} else if (OS_IOS) {
//Here we have two cases: App was closed or App still running;
handleResponse(Ti.App.getArguments().url);
Ti.App.addEventListener('resume', function () {
handleResponse(Ti.App.getArguments().url);
});
}
});
After all, you can develop your handleResponse function :)
The receiving parameter it will be the URL from the another app,now you only need to parse.
--
As an alternative, since version 5.2, Titanium supports the Hyperloop [beta] module. You can use it to integrate the native paypal-ios sdk to your Titanium App. Maybe it will be more better documented and easy to maintain. You can install using CocoaPods, and access directly via Hyperloop. If you have interest this is a good start point: How to use Hyperloop in your Titanium App