簡體   English   中英

PayPal-Ruby-SDK Web體驗配置文件創建

[英]PayPal-Ruby-SDK web-experience-profile creation

我是一個新的Rails開發人員,在使用REST API處理付款之前,我不了解Paypal的文檔來創建Web體驗配置文件

只要我不嘗試使用體驗資料,就可以使用下面的代碼付款。

調試時,我得到的@webprofile值類似於:

#<PayPal::SDK::REST::DataTypes::WebProfile:0x007fe0f9344e50 @error=nil, 
@name="YeowZa! T-Shirt Shop", @presentation=#<PayPal::SDK::REST::DataTypes::Presentation:0x007fe0f8ec51b8 @error=nil, @brand_name="YeowZa! Paypa
l", @logo_image="http://www.yeowza.com", @locale_code="US">, @input_fields=#<PayPal::SDK::REST::DataTypes::InputFields:0x007fe0f927b0f0 @error=nil, @allow_note=true, @no_shipping=0, @address_override=1>, @flow_config
=#<PayPal::SDK::REST::DataTypes::FlowConfig:0x007fe0f90808e0 @error=nil, @landing_page_type="billing", @bank_txn_pending_url="http://www.yeowza.com">, @request_id="bcc4bc41-b61c-4d28-94f1-a0912121d8e8", @header={}>

在我的控制台上,我看到:請求[發布]: https : //api.sandbox.paypal.com/v1/payment-experience/web-profiles/
響應[400]:錯誤的請求,

到目前為止,我的代碼是:

class PaypalController < ApplicationController
  require 'paypal-sdk-rest'
  include PayPal::SDK::REST
  include PayPal::SDK::Core::Logging

  def create 
    PayPal::SDK::REST.set_config(
    :mode => "sandbox", # "sandbox" or "live"
    :client_id => "my-id",
    :client_secret => "my-secret")

    # Build Payment object
    @payment = Payment.new({ 

      :intent => "sale",
      :payer => {
      :payment_method => "paypal"},
      :experience_profile_id => self.web_experience,
      :redirect_urls => {
        :return_url => "http://me.com/paypal_complete",
        :cancel_url => "http://me.com/paypal_cancel"},

        :transactions => [{
          :item_list => {
            :items => [{
              :name => "me.com Thing",
              :sku => "the-specific-horse",
              :price => "2",
              :currency => "USD",
              :quantity =>  "1" }]},
          :amount => {
            :total => "2.00",
            :currency => "USD" },
          :description => "Payment for the-specific-thing" }]
        })

      # Create Payment and return the status(true or false)
    if @payment.create
      # Redirect the user to given approval url
      @redirect_url = @payment.links.find{|v| v.method == "REDIRECT" }.href
      logger.info "Payment[#{@payment.id}]"
      logger.info "Redirect: #{@redirect_url}"
      redirect_to @redirect_url
    else
      logger.error @payment.error.inspect
    end
  end

  def paypal_complete
    begin
      # paymentId: PAY-8L3183743T450642VKWDPH7I
      # token: EC-57E34614K6825515M
      # PayerID: RBWLMFNFF4ZUC
      payment_id = params[:paymentId]
      # Retrieve the payment object by calling the
      # `find` method
      # on the Payment class by passing Payment ID
      @payment = Payment.find(payment_id)
      logger.info "Got Payment Details for Payment[#{@payment.id}]"

    rescue ResourceNotFound => err
      # It will throw ResourceNotFound exception if the payment not found
      logger.error "Payment Not Found"
    end
  end

  def web_experience
    #this is not used right now...don't know how
    @webprofile = WebProfile.new(
        {
        :name => "YeowZa! T-Shirt Shop",
        :presentation => {
            :brand_name => "YeowZa! Paypal",
            :logo_image => "http://www.yeowza.com",
            :locale_code => "US"
        },
        :input_fields => {
            :allow_note => true,
            :no_shipping => 0,
            :address_override => 1
        },
        :flow_config => {
            :landing_page_type => "billing",
            :bank_txn_pending_url => "http://www.yeowza.com"
        }
        })  

        if @webprofile.create
          # Redirect the user to given approval url

          logger.info "@webprofile[#{@webprofile}]"
          debugger
        else
          logger.error @payment.error.inspect
          debugger
        end
  end
end

這很老,但我認為其他人可能會像我一樣最終來到這里。

.NET SDK也有類似的問題。 通過從請求對象中刪除本不應該使用的字段來解決該問題,即我已將字段bank_txn_pending_url設置為空字符串,而當我根本沒有定義此字段時(等於null),請求返回200 。它在文檔中明確指出僅在某些情況下才應在德國使用此字段。

不過,一旦創建,后續請求就會失敗,因為您不能擁有兩個具有相同名稱的配置文件。 您需要獲取現有配置文件的列表,並使用現有的ID(如果找到)。 無需一遍又一遍地創建。

Bummer儀表板無法捕獲事務部分中的所有請求,如果這樣做,將使工作變得更加輕松。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM