Mashhood
Mashhood

Reputation: 403

paypal let my site users pay each other

I am working on a project where I want my users to be able to pay each other for the services they provide using my site.
I went through https://github.com/paypal/adaptivepayments-sdk-ruby and did every step mentioned there but I was not being redirected to paypal upon execution of that code but just a mere status: 200 comes in RAILS SERVER logs.

May be my understanding is not correct about it. Please guide.


After that, Now I'm trying to go with this https://launchschool.com/blog/basic-paypal-checkout-processing-in-rails tutorial and was able to successfully do payment in sandbox environment.

But the issue with this approach is that upon successful payment, it doesn't automatically redirect me back so that I'd be able to insert that payment info into my system as well.
Yes, I know that I have to turn on "auto return" in my business account SETTINGS but that is only feasible when payments are directly being made to me.

What if users pay to each other? How do I redirect them back as I obviously won't have access to their ACCOUNT SETTINGS.


In a nutshell, I just want to enable my users to pay each other and I want that info to be inserted into my system as well.

Any suggestions because I may not be aware of how paypal works?


here is the code:

controller:

def create
   @transaction = Transaction.new(transaction_params)
   @transaction.user_id =  current_user.id

   redirect_to @transaction.paypal_url(root_path)
end

model

def paypal_url(return_path)
raw_config = File.read("#{Rails.root}/config/paypal.yml")
paypal_CONFIG = YAML.load(raw_config)

values = {
    business: "[email protected]",
    cmd: "_xclick",
    upload: 1,
    returnurl: paypal_CONFIG[Rails.env]['app_host']+"#{return_path}",
    invoice: id,
    amount: self.total_amount,
    item_name: "Purchase Order",
    quantity: '1',
    notify_url: paypal_CONFIG[Rails.env]['app_host']+"/hook",
}

paypal_CONFIG[Rails.env]['paypal_host']+"/cgi-bin/webscr?" + values.to_query
end

paypal.yml

development:
   paypal_host: https://www.sandbox.paypal.com
   app_host: http://our_ngrok_url

production:
   paypal_host: https://www.paypal.com
   app_host: https://ourdomain.com/

Upvotes: 0

Views: 434

Answers (1)

charis_r
charis_r

Reputation: 36

I believe you are not using the best approach in the first hand. If you are the website owner and you want to allow part of your users (i.e. buyers) to pay another part (i.e. sellers) for services/products rendered, you should consider acting as the intermediate, to keep the transaction info to your account and pass it to your backend (also ensure security and help resolving issues, refunds etc). This is a classic approach for marketplace type of sites, which I believe is what you are doing.

So instead of a buyer paying the seller directly, the buyer pays you, you then update the seller's balance and the buyer then withdraws from his account. This entire can be set up with PayPal and can be done with Payouts and Mass Pay.

Once you setup the basic stuff, charging, updating balances etc, setting up redirects and passing the transaction info to your backend is the easy part.

The docs above are your friend.

Hope that helps. If you need further help let me know.

Upvotes: 1

Related Questions