Yes it is possible. I have just implemented a code my application where my customer leaves my application site and goes to paypal page. Customer logs in and clicks "I agree" and gets back to my application/site.
I am using Spring framework. The first call that I mentioned above is where Paypal send me a token which I can use to actually charge the customer account. When customers reviews the final order on my site and decides to submit, I use this token and give a call to Paypal to charge the account.
How I am doing this:
Customer chooses option: I want to pay via Paypal. The call comes to my servlet.
Step 1. Get the paypal token. You will need to call the PayPal Api to get the token. Check Paypal developer guide.
Step 2. "Forward" customer to Paypal site by appending the token(REMEBER NEVER SEND PAYMENT INFORMATION IN THE URL.)
I fill in Paypal business value object (customer name, email, price, currecny etc.). Then I am forwarding the customer to this URL
String forwardUrl =
https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=" + paypalResponseVO.getPayPalResponseVO().getApiToken();
Step3: After customer clicks agree on Paypal URL. Paypal automatically redirects the customer to my site. How is that possible. When you requested token number in step one, you pass information such as CancelUrl, SuccessUrl. Paypal uses this url to forward customer back to your site.
So now in my forward URL I have provided logic that if everything was fine then take the customer to the next page.
Step 4. Customer reviews the order and asks to charge the Paypal account. Use the same token number and send a another request to Paypal API to charge the account.