首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >PayPal-Ruby-SDK web-experience-profile创建

PayPal-Ruby-SDK web-experience-profile创建
EN

Stack Overflow用户
提问于 2015-06-22 06:54:06
回答 1查看 376关注 0票数 1

我是一个新的rails开发人员,在使用REST API处理支付之前,我对create a web experience profile没有理解贝宝的文档:

我可以用下面的代码支付ok,只要我不尝试使用经验配置文件。

在调试时,我得到一个@webprofile的值,类似于:

代码语言:javascript
复制
#<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={}>

在我的控制台上,我看到: Requestpost:https://api.sandbox.paypal.com/v1/payment-experience/web-profiles/

Response400:错误的请求,

到目前为止我的代码是:

代码语言:javascript
复制
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
EN

回答 1

Stack Overflow用户

发布于 2016-03-04 19:26:22

这是旧的,但我想其他人可能会像我一样结束在这里。

我在使用.NET SDK时也遇到了类似的问题。通过从请求对象中删除我不应该使用的字段,即我设置为空字符串的字段bank_txn_pending_url,当我根本没有定义这个字段(相当于null)时,请求返回200。它在文档中明确指出,该字段仅应在某些情况下在德国使用。

一旦创建,后续的请求就会失败,因为您不能拥有两个同名的概要文件。您需要获取现有配置文件的列表,如果找到,则使用现有ID。不需要一遍又一遍地创建。

不幸的是,仪表板没有捕获事务部分中的所有请求,如果它捕获了所有请求,将会使工作变得容易得多。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30970128

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档