【问题标题】:How to integrate Paypal with Ruby on Rails如何将 Paypal 与 Ruby on Rails 集成
【发布时间】:2014-06-18 03:30:27
【问题描述】:

我正在尝试使用 rest-api-sdk-ruby gem (https://github.com/paypal/rest-api-sdk-ruby) 将 paypal 与我的 ruby​​ on rails 应用程序集成,但找不到足够的信息或好的教程来支持我。 上面提供的描述虽然提供了必要的代码,但并未说明如何处理方法周围的方法或每个方法应转到哪些文件。

谁能在这里给我一个起点或给我一个好的教程?

我使用的是 Rails 版本 4。

非常感谢。

【问题讨论】:

    标签: ruby-on-rails ruby paypal


    【解决方案1】:

    这里给出了详细的分步过程

    使用基本的 Checkout 方法将 Paypal 集成到您的 Rails 应用程序:
    Basic Checkout

    如果您想接受信用卡付款:
    Charge Credit Cards

    如果您想接受定期付款:
    Recurring Payments

    您可以克隆此应用并在本地计算机中进行测试

    git clone https://github.com/gotealeaf/paypal-basics
    cd paypal-basics
    rake db:create
    rake db:migrate
    rake db:seed
    rails s
    

    【讨论】:

    • 为您的链接唯一答案提供一些上下文和解释!
    【解决方案2】:

    标准 PayPal 与 Rails 应用 Active Merchant gem 集成

    步骤 1

    • 在 您的 Gemfile 中添加 gem 'activemerchant'

    • 运行bundle install

    第二步

    • 转到“developer.paypal.com”并使用美国地址详细信息创建一个帐户(也称为商家帐户)。

      它将在“sandbox.paypal.com”中创建两个虚拟测试帐户,买方和卖方(也称为促进者)各一个。要查看测试帐户详细信息,请单击“仪表板 -> 帐户”

    • 现在通过单击配置文件链接为两个测试帐户设置密码。

    第三步

    • 转到卖家账户(即服务商)资料详情并复制 API 凭据,即用户名、密码和签名。例如:

      Username:  naveengoud-facilitator_api1.gamil.com
      Password:  VSPALJ5ALA5YY9YJ
      Signature: AVLslxW5UGzEpaDPEK4Oril7Xo4IAYjdWHD25HhS8a8kqPYO4FjFhd6A
      
    • 在“config/environments/development.rb”中设置这些 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
      

    第四步

    【讨论】:

    • 该视频是 2009 年的,无法加载 :(
    【解决方案3】:

    我参加聚会有点晚了,但我在 PayPal 文档中找到了这个

    PayPal 付款涉及以下 3 个步骤:

    • 指定付款信息以创建付款。
    • 获得付款批准。
    • 向 PayPal 用户的帐户执行付款。

    1) 将intent设置为sale,将payment_method设置为paypal

    包括重定向 URL。用户在批准或取消付款时会被重定向到这些 URL。

    curl https://api.sandbox.paypal.com/v1/payments/payment \
      -v \
      -H 'Content-Type: application/json' \
      -H 'Authorization: Bearer accessToken' \
      -d '{
        "intent":"sale",
        "redirect_urls":{
          "return_url":"http://return_URL_here",
          "cancel_url":"http://cancel_URL_here"
        },
        "payer":{
          "payment_method":"paypal"
        },
        "transactions":[
          {
            "amount":{
              "total":"7.47",
              "currency":"USD"
            },
            "description":"This is the payment transaction description."
          }
        ]
      }
    

    回复:

    {
      "id":"PAY-6RV70583SB702805EKEYSZ6Y",
      "create_time":"2013-03-01T22:34:35Z",
      "update_time":"2013-03-01T22:34:36Z",
      "state":"created",
      "intent":"sale",
      "payer":{
        "payment_method":"paypal"
      },
      "transactions":[
        {
          "amount":{
            "total":"7.47",
            "currency":"USD",
            "details":{
              "subtotal":"7.47"
            }
          },
          "description":"This is the payment transaction description."
        }
      ],
      "links":[
        {
          "href":"https://api.sandbox.paypal.com/v1/payments/payment/PAY-6RV70583SB702805EKEYSZ6Y",
          "rel":"self",
          "method":"GET"
        },
        {
          "href":"https://www.sandbox.paypal.com/webscr?cmd=_express-checkout&token=EC-60U79048BN7719609",
          "rel":"approval_url",
          "method":"REDIRECT"
        },
        {
          "href":"https://api.sandbox.paypal.com/v1/payments/payment/PAY-6RV70583SB702805EKEYSZ6Y/execute",
          "rel":"execute",
          "method":"POST"
        }
      ]
    }
    

    2) 获得付款批准

    请注意上面示例中的 HATEOAS 链接。将用户引导至 PayPal 网站上的approval_url,以便用户批准付款。用户必须先批准付款,然后您才能执行和完成销售。

    3) 执行付款

    当用户批准付款时,PayPal 将用户重定向到指定的 return_url

    付款创建时间。付款人 ID 和付款 ID 附加到返回 URL,如 PayerIDpaymentId

    http://return_url?paymentId=PAY-6RV70583SB702805EKEYSZ6Y&token=EC-60U79048BN7719609&PayerID=7E7MGXCWTTKK2
    

    执行支付时不需要附加到返回 URL 的令牌值。

    要在用户批准后执行付款,请拨打/payment/execute/ 电话。在请求正文中,使用附加到返回 URL 的 payer_id 值。在标头中,使用您在创建付款时使用的访问令牌。

    curl https://api.sandbox.paypal.com/v1/payments/payment/PAY-6RV70583SB702805EKEYSZ6Y/execute/ \
      -v \
      -H 'Content-Type: application/json' \
      -H 'Authorization: Bearer accessToken' \
      -d '{ "payer_id" : "7E7MGXCWTTKK2" }'
    

    注意:付款完成后,称为销售。然后,您可以查看销售情况并进行退款。

    希望对你有帮助!

    【讨论】:

      猜你喜欢
      • 2015-09-05
      • 2013-09-18
      • 2013-09-29
      • 2016-08-10
      • 2012-10-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多