简体   繁体   English

PayPal集成Ruby on Rails

[英]PayPal integration Ruby on Rails

I've seen posts that you should use ActiveMerchant for PayPal integration, but I also found this on the PayPal website.I'm struggling with placing what in which file, since I'm totally new to RoR. 我已经看到你应该使用ActiveMerchant进行PayPal集成的帖子,但我也在PayPal网站上找到了这个帖子。我正在努力将文件放在哪个文件中,因为我对RoR完全不熟悉。 So I was trying to integrate the PayPal , but am not sure where to place which code. 所以我试图整合PayPal ,但不知道在哪里放置哪些代码。

Should I use active merchant for PayPal integration, or is the Rest-API the best choice. 我应该使用活动商家进行PayPal集成,还是Rest-API是最佳选择。 I want people to fill out their username, pay and when successful they receive digital content. 我希望人们填写用户名,付费,并在成功时收到数字内容。 So there should be a call with a result and the username. 所以应该有一个结果和用户名的调用。

Do you have a link, step by step, at least including which code I should place in which file, so I get the basics of RoR better. 你有一个循序渐进的链接,至少包括我应该在哪个文件中放置哪些代码,所以我更好地了解了RoR的基础知识。

I found the PayPal API documentation to be quite confusing. 我发现PayPal API文档非常混乱。 Also, my application requirements were not satisfied through the API, so I ended up with a rather simple solution. 此外,通过API不满足我的应用程序要求,因此我最终得到了一个相当简单的解决方案。

The solution mainly consists of two components: 解决方案主要包括两个组成部分:

  1. PayPal buttons, which I generate on PayPal website and copy the HTML to my website PayPal按钮,我在PayPal网站上生成并将HTML复制到我的网站
  2. PayPal IPN notifications, for which I have a simple handler on my website PayPal IPN通知,我的网站上有一个简单的处理程序

This is how the whole solution works in detail 这就是整个解决方案的详细工作方式

  1. For the user to make payments, I use the PayPal Buttons. 为了让用户付款,我使用PayPal按钮。 For this, you just login to your PayPal business account and generate HTML code for buttons which you can copy and paste into your website. 为此,您只需登录您的PayPal商业帐户并生成按钮的HTML代码,您可以将其复制并粘贴到您的网站中。
  2. The user can click on these buttons, they will be redirected to PayPal website, they make payments and have a button to come back to your website. 用户可以点击这些按钮,他们将被重定向到PayPal网站,他们付款并有一个按钮返回您的网站。
  3. When the transaction is done (either success or failure), PayPal will inform you via PayPal IPN Notifications. 交易完成后(成功或失败),PayPal将通过PayPal IPN通知通知您。 I have implemented an IPN handler on my website, which was quite easy to do. 我在我的网站上实现了一个IPN处理程序,这很容易做到。
  4. By the time the user returns to my website, in most cases, I would have already got the IPN notification, hence I can show them a success message. 当用户返回我的网站时,在大多数情况下,我已经获得了IPN通知,因此我可以向他们显示成功消息。
  5. In case the IPN got delayed, I tell the users that it will take a couple more minutes to update their balance and use AJAX to keep querying the server for updates. 如果IPN延迟,我告诉用户,更新余额需要花费几分钟时间,并使用AJAX继续查询服务器的更新。

Here are some useful references: 以下是一些有用的参考:

  1. PayPal Buttons 贝宝按钮
  2. Rail Casts on PayPal IPN 铁路投资于PayPal IPN
  3. If you need, you can also dynamically generate the buttons via the Button Manager API gem 如果需要,还可以通过Button Manager API gem动态生成按钮

Standard PayPal Integration with Rails app Active Merchant gem : 标准PayPal与Rails应用程序集成Active Merchant gem:

step 1: 第1步:

-> add 'gem activemerchant' in gem file - >在gem文件中添加'gem activemerchant'

-> bundle install - >捆绑安装

step 2: 第2步:

-> Go to "www.developer.paypal.com" and create an account(also known as Merchant Account) with US address details. - >转到“www.developer.paypal.com”并创建一个包含美国地址详细信息的帐户(也称为商家帐户)。

-> It will create two dummy test account for buyer and seller(alias facilitator) in "sandbox.paypal.com". - >它将在“sandbox.paypal.com”中为买方和卖方(别名协调人)创建两个虚拟测试帐户。

Ex: 例如:
Seller account ---> naveengoud-facilitator@gmail.com 卖家账号---> naveengoud-facilitator@gmail.com
Buyer account ---> naveengoud-buyer@gmail.com 买家帐号---> naveengoud-buyer@gmail.com

-> To see test accounts details Click on "Dashboard -> Accounts" - >查看测试帐户详细信息单击“仪表板 - >帐户”

-> Now set the password for both test accounts by clicking on profile link - >现在通过单击配置文件链接为两个测试帐户设置密码

step 3: 第3步:

-> Go to seller account(ie, facilitator) profile details and copy the API Credentials ie, Username, password and signature - >转到卖家帐户(即协调人)个人资料详细信息并复制API凭据,即用户名,密码和签名

Ex: 例如:
Username: naveengoud-facilitator_api1.gamil.com 用户名:naveengoud-facilitator_api1.gamil.com
Password: VSPALJ5ALA5YY9YJ 密码:VSPALJ5ALA5YY9YJ
Signature: AVLslxW5UGzEpaDPEK4Oril7Xo4IAYjdWHD25HhS8a8kqPYO4FjFhd6A 签名:AVLslxW5UGzEpaDPEK4Oril7Xo4IAYjdWHD​​25HhS8a8kqPYO4FjFhd6A

-> Set these API Credentials in "config/environments/development.rb" as follows, add the below code with API credentials - >如下所示在“config / environments / development.rb”中设置这些API凭据,使用API​​凭据添加以下代码

  config.after_initialize do  
ActiveMerchant::Billing::Base.mode = :test         
        ::GATEWAY = ActiveMerchant::Billing::PaypalGateway.new(  
             login: "merchant_api1.gotealeaf.com",  
            password: "2PWPEUKZXAYE7ZHR",  
            signature: "AFcWxV21C7fd0v3bYYYRCpSSRl31A-dRI5VpyF4A9emruhNYzlM8poc0"  
        )  
     end

step 4: 第四步:

-> From here onward follow the Rails cast 145 episode( http://railscasts.com/episodes/145-integrating-active-merchant ) - >从这里开始关注Rails演员阵容145集( http://railscasts.com/episodes/145-integrating-active-merchant

This link will help you to get better understanding on integration of Basic Checkout, Charge Credit Cards and Recurring Payments with paypal in Ruby On Rails application 此链接将帮助您更好地了解基本结账,充值信用卡和定期付款与Ruby On Rails应用程序中的paypal的集成

http://www.gotealeaf.com/blog/basic-paypal-checkout-processing-in-rails http://www.gotealeaf.com/blog/basic-paypal-checkout-processing-in-rails

You can find solutions for following concepts, 您可以找到以下概念的解决方案,

1) Basic Checkout 2) Charge Credit Cards 3) Recurring Payments 1)基本结账2)充值信用卡3)定期付款

Look at this for rails integration: 看看这个用于rails集成:

but also here, more in general (less related to Rails): 但也在这里,更一般(与Rails相关性较小):

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM