Authorize.net: "There is one or more missing or invalid required fields." 但它没有说明丢失或无效的内容

Authorize.net: "There is one or more missing or invalid required fields." But it doesn't say what's missing or invalid

我正在实施客户资料。我几乎一字不差地从示例中获取了代码。当我尝试创建客户资料时,它抱怨缺少一个字段,但没有指定是哪个字段。怎么了?

https://developer.authorize.net/api/reference/index.html#customer-profiles-create-customer-profile

payment_profiles_controller.rb
  def create
    @payment_profile = ::PaymentProfile.new pp_params # my model, not theirs
    unless @payment_profile.valid?
      flash.now.alert = @payment_profile.errors.full_messages.join(', ')
      render :new and return
    end
    # create authorize.net customer profile
    if Rails.env == 'production'
      transaction = Transaction.new(ENV['AUTHORIZENET_LOGIN_ID'], ENV['AUTHORIZENET_TRANSACTION_KEY'], :gateway => :production)
    else
      transaction = Transaction.new(ENV['AUTHORIZENET_LOGIN_ID'], ENV['AUTHORIZENET_TRANSACTION_KEY'], :gateway => :sandbox)
    end

    # Build the payment object
    payment = PaymentType.new(CreditCardType.new)
    payment.creditCard.cardNumber = pp_params[:card_number]
    payment.creditCard.expirationDate = pp_params[:expiration_date]

    # Build an address object
    billTo = CustomerAddressType.new
    billTo.firstName = pp_params[:first_name]
    billTo.lastName = pp_params[:last_name]
    billTo.company = pp_params[:company]
    billTo.phoneNumber = pp_params[:phone]
    billTo.address = pp_params[:address]
    billTo.city = pp_params[:city]
    billTo.state = pp_params[:state]
    billTo.zip = pp_params[:zip]
    billTo.country = pp_params[:country]

    # Use the previously defined payment and billTo objects to
    # build a payment profile to send with the request
    paymentProfile = CustomerPaymentProfileType.new
    paymentProfile.customerType = 'business'
    paymentProfile.payment = payment
    paymentProfile.billTo = billTo
    paymentProfile.defaultPaymentProfile = true

    # Build the request object
    request = CreateCustomerProfileRequest.new
    # Build the profile object containing the main information about the customer profile
    request.profile = CustomerProfileType.new
    request.profile.merchantCustomerId = @user.id
    request.profile.email = @user.email
    # Add the payment profile and shipping profile defined previously
    request.profile.paymentProfiles = [paymentProfile]
    request.validationMode = ValidationModeEnum::LiveMode    

    response = transaction.create_customer_profile(request)

    if response != nil
      byebug
      puts response.messages.resultCode
      if response.messages.resultCode == MessageTypeEnum::Ok
        puts "Successfully created a customer profile with id: #{response.customerProfileId}"
        puts "  Customer Payment Profile Id List:"
        response.customerPaymentProfileIdList.numericString.each do |id|
          puts "    #{id}"
        end
        puts "  Customer Shipping Address Id List:"
        response.customerShippingAddressIdList.numericString.each do |id|
          puts "    #{id}"
        end
        puts 
        @subscription.create_authorizenet user: @user, customer_profile_id: response.customerProfileId, customer_payment_profile_id: response.customerPaymentProfileIdList.numericString.first
        redirect_to dashboard_path, notice: 'Customer payment profile saved.'
      else
        puts response.messages.messages[0].code
        puts response.messages.messages[0].text
        flash.now.alert = "Failed to create a new customer profile: #{response.messages.messages[0].code} #{response.messages.messages[0].text}"
        render :new
      end
    else
      puts "Response is null"
      flash.now.alert = "Failed to create a new customer profile."
      render :new
    end
  end

控制台

Started POST "/users/1/subscription/payment_profile" for 127.0.0.1 at 2018-03-12 22:02:32 -0400
Processing by PaymentProfilesController#create as HTML
  Parameters: {"utf8"=>"√", "authenticity_token"=>"HsKjEiR6ulTSPN0GzwfmAa2bG1LV6Lixp8TW4lNcJZVlxPP1v/46GAr7NGqdjQ47eV20ZWWDVjsf1TwpsfaRhQ==", "payment_profile"=>{"card_number"=>"4111111111111111", "expiration_date"=>"2018-11", "first_name"=>"Sue", "last_name"=>"D. Nym", "company"=>"Acme Corp.", "phone"=>"212-222-3333", "address"=>"2 Wall St.", "city"=>"New York", "state"=>"NY", "country"=>"United States"}, "commit"=>"Save", "user_id"=>"1"}
...
(byebug) response.messages
#<AuthorizeNet::API::MessagesType:0x000000102e5a08 @resultCode="Error", @messages=[#<AuthorizeNet::API::MessagesType::Message:0x000000102bd148 @code="E00027", @text="There is one or more missing or invalid required fields.", @roxml_references=[#<ROXML::XMLTextRef:0x000000102bd030 @opts=#<ROXML::Definition:0x000000066e5d88 @default=nil, @to_xml=nil, @name_explicit=false, @cdata=nil, @required=nil, @frozen=nil, @wrapper=nil, @namespace=nil, @accessor="code", @array=false, @blocks=[], @sought_type=:text, @attr_name="code", @name="code">, @instance=#<AuthorizeNet::API::MessagesType::Message:0x000000102bd148 ...>, @default_namespace="xmlns">, #<ROXML::XMLTextRef:0x000000102bd008 @opts=#<ROXML::Definition:0x000000066e5540 @default=nil, @to_xml=nil, @name_explicit=false, @cdata=nil, @required=nil, @frozen=nil, @wrapper=nil, @namespace=nil, @accessor="text", @array=false, @blocks=[], @sought_type=:text, @attr_name="text", @name="text">, @instance=#<AuthorizeNet::API::MessagesType::Message:0x000000102bd148 ...>, @default_namespace="xmlns">]>], @roxml_references=[#<ROXML::XMLTextRef:0x000000102e5760 @opts=#<ROXML::Definition:0x000000066e4ac8 @default=nil, @to_xml=nil, @name_explicit=false, @cdata=nil, @required=nil, @frozen=nil, @wrapper=nil, @namespace=nil, @accessor="resultCode", @array=false, @blocks=[], @sought_type=:text, @attr_name="resultCode", @name="resultCode">, @instance=#<AuthorizeNet::API::MessagesType:0x000000102e5a08 ...>, @default_namespace="xmlns">, #<ROXML::XMLObjectRef:0x000000102e5738 @opts=#<ROXML::Definition:0x00000008cc7fb0 @default=nil, @to_xml=nil, @name_explicit=false, @cdata=nil, @required=nil, @frozen=nil, @wrapper=nil, @namespace=nil, @accessor="messages", @array=true, @blocks=[], @sought_type=AuthorizeNet::API::MessagesType::Message, @attr_name="messages", @name="message">, @instance=#<AuthorizeNet::API::MessagesType:0x000000102e5a08 ...>, @default_namespace="xmlns">]>
(byebug) response.messages.messages.length
1
(byebug) c
Error
E00027
There is one or more missing or invalid required fields.

我发现视图中缺少邮政编码。

  .form-group
    =f.label :zip
    =f.text_field :zip, class: 'form-control'

我希望它能告诉我。