Post form to paypal

Hello, i have this form that i need to post to paypal, and when i do it posts in the same view. I can finish the process , but there’s no way i can get back to my app, say i came from /#/app/home and i end up here https://www.sandbox.paypal.com/cgi-bin/webscr#m-3

Also , paypal can return to an arbitrary url after completing the payment, but that’s useless since i can not return to the app from there, i tried a link with href like ‘file:///android_asset/www/index.html#/app/home’ but no go. It does work when i redirect from the server callback url to my local dev server localhost:8100/#/app/home but that is also useless on the phone since there’s no running server there only static files.

My only hope was to somehow submit the form in a new window which i could close when done, and this way i would never loose my app after submit, so i tried the inappbrowser plugin with target _blank but that only accepts an url , not arbitrary html like my form (well yea i did put my form in an external template and loaded that with window.open, and at the bottom of the file i had this javascript that would submit the form when loaded, but in that case i can’t modify my form before submitting, or maybe yes by injecting js into the inappbrowser ref but that would be crappy).

So, the question was… can i submit a form in a new window or something or maybe a way to get back to the app after i submitted the form.

Next thing is to try is to poll window.location.href after i submit the form, and when it matches my server callback url where paypal will redirect after success, maybe try to use state.go or something to get back “home”…

Any thoughts?

I just ran into the same issue. In case it still helps: I worked around this problem by using the inapp browser loadstart event and checking the url for my payment-confirmation and cancellation urls. Then you can do ref.close() to return back out of the inapp browser. See the documentation here: https://github.com/apache/cordova-plugin-inappbrowser

I did more of the same, but i used loadstop event and checked the backend url for confirmation or anything, then do ref.close

6 months after this question was asked, i have searched this forum and have not found any good solution to this problem. I having this same issue right now and i would appreciate any help

var ref = window.open(your_backend_url, ‘_blank’, ‘cache=no,location=no’);

// use this to return to some state after the external browser is closed
ref.addEventListener(‘exit’, function() {
$state.go(your_state, {reload:true});
});

// close the external browser when hitting confirmation or error (your backend needs to redirect to a route you can catch here)
ref.addEventListener(‘loadstop’, function(event) {
if (event.url.match("/api/confirmed") || event.url.match("/api/cancel") || event.url.match("/api/error")) {
$timeout(function () {
ref.close();
}, 15000);
}
});

1 Like