Coder Social home page Coder Social logo

Comments (6)

jpablobr avatar jpablobr commented on June 2, 2024

I feel your pain :/ but that is very paypay/rails specific logic and kind of out of the scope of this gem.

That said, are you using spree? if so, your controller has to look kind of like this?

https://github.com/spree/spree_paypal_express/blob/master/app/controllers/spree/checkout_controller_decorator.rb

That's based on PayPal Express, but it's a bit similar. I've been trying open-source a decent version of the PayPal Adaptive payments for spree here, but haven't got the time to finish it. 😞

Hope that makes scene and helps you a bit, anything else just post it here and I'll try to help as much as possible.

from active_paypal_adaptive_payment.

cmezak avatar cmezak commented on June 2, 2024

I've figured out how to put the URL together. It's
"https://www.sandbox.paypal.com/webscr?cmd=_ap-preapproval&preapprovalkey=" + @payment.preapproval_key

Then I have to go through the source to figure out how to assemble the options hash for preapprove_payment. If I can, when I'm through with all of this, I'll contribute to the documentation and code.

from active_paypal_adaptive_payment.

jpablobr avatar jpablobr commented on June 2, 2024

That URL is already being handled by the gem here.

Basically this is how a payment process should look like:

  1. Process the payment/order in your checkout_controller#payment action:
# req = the Hash with all the order/payment required options.
session[:adaptive_payment_response] = gateway.setup_purchase(req)
  1. Then session[:adaptive_payment_response] should be full of a bunch
    of PayPal info/crap regarding that first payment request.

  2. You then - in that #payment action - need to verify if its successfull.

if session[:adaptive_payment_response].success?
  # confirmation key for the second request
  redirect_to (gateway.redirect_url_for(session[:adaptive_payment_response][:pay_key])) # redirecting again...
else
  gateway_error(session[:adaptive_payment_response])
  redirect_to edit_order_checkout_url
end
  1. Now you need another checkout_controller#action to receive what PayPal
    is - again - sending you. The last and confirmed request.

  2. profit :/

from active_paypal_adaptive_payment.

cmezak avatar cmezak commented on June 2, 2024

Hi jpablobr,

Thanks for taking the time to explain this, but I'm not sure if it fits with what I'm doing.

On my site, users can request to receive periodic automatic orders of our products, so I need to set up the a pre approved payment agreement. I don't need to actually execute a payment at this point, just to set up the preapproval agreement so I can do the automatic payments in the future.

The first step is to use preapprove_payment to get the preapproval key. Then I have to send the user to paypal with the key so they can log into paypal and approve it. That's what I figured out in my previous post. I actually saw that url in the source code, but how am I supposed to use it in my code?

Once the user has authorized the preapproves payment key, I get an IPN to let my site know that it's been authorized. From the on, I should be able to use the key to make purchases without needing the user to log in. Haven't tried to figure that one out yet, though. : )

I'm loosely basing my approach to this on ryanb's railscasts for integrating paypal into a rails app.

from active_paypal_adaptive_payment.

jpablobr avatar jpablobr commented on June 2, 2024

I haven't played much with preapprove_payment, but it should have to be similar to the other requests.

The gateway.setup_purchase(req) (setup_purchase) will build the request which in turn will give you the key.

Then, the redirect_url_for (in this case using Rail's redirect_to):

redirect_to (gateway.redirect_url_for(session[:adaptive_payment_response][:pay_key]))

will send the user to PayPal's website to handle the specified type of request (in your case a preapprove_payment). Once in there, based on what the user did, PayPal will send to your application one last "response" basically containing those user actions.

All these in the same way I mentioned on my previous comment.

One more caveat... that last request is not an IPN. IPNs are handled differently. However, the IPN is not required... but is obviously helpful since that will let your application know the status of the whole transaction. Basically without it you are blind, but the preapprove_payment (successful or not) will be "successfully" completed (if the user accepted it or not). <3 PayPal :trollface:

from active_paypal_adaptive_payment.

jpablobr avatar jpablobr commented on June 2, 2024

Hey I'm closing the issue since this is not specific to the gem... Feel free to open it again if you think is necessary.

from active_paypal_adaptive_payment.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.