2014-04-29 2 views
1

고객을 만들 때 braintree API로 카드 확인을하려고합니다.브레인 트리 및 레일로 신용 카드 확인이 작동하지 않습니다.

@braintree_id = "#{current_user.profile_name}" + rand(5..1000).to_s 
@result = Braintree::Customer.create(
    :id => @braintree_id, 
    :first_name => employer_account_params[:first_name], 
    :last_name => employer_account_params[:last_name], 
    :company => employer_account_params[:company], 
    :email => employer_account_params[:email], 
    :phone => employer_account_params[:phone], 
    :fax => employer_account_params[:fax], 
    :website => employer_account_params[:website], 
    :credit_card => { 
     :number => employer_account_params[:credit_card][:number], 
     :expiration_date => employer_account_params[:credit_card][:expiration_date], 
     :billing_address => { 
      :street_address => employer_account_params[:credit_card][:billing_address][:street_address], 
      :extended_address => employer_account_params[:credit_card][:billing_address][:extended_address], 
      :locality => employer_account_params[:credit_card][:billing_address][:locality], 
      :region => employer_account_params[:credit_card][:billing_address][:region], 
      :postal_code => employer_account_params[:credit_card][:billing_address][:postal_code], 
      :country_code_alpha2 => employer_account_params[:credit_card][:billing_address][:country_code_alpha2] 
     }, 
     :options => { 
      :verify_card => true 
      } 
    } 
) 
puts 'result is ' + @result.inspect.to_s 
@verification = @result.credit_card_verification 
puts 'verification' + @verification.inspect.to_s 
puts 'card results: ' + @verification.gateway_rejection_reason.to_s 

문제가 credit_card_verification에 관계없이 반환 true 또는 false @Result 여부, 항상 무기 호입니다 : 여기에 고객을 생성하는 코드입니다.

11:57:32 web.1 | result is #<Braintree::SuccessfulResult customer:#<Braintree::Customer id: "person2359", company: nil, email: nil, fax: nil, first_name: "sgdgsfd", last_name: nil, phone: nil, website: nil, created_at: 2014-04-29 15:57:32 UTC, updated_at: 2014-04-29 15:57:32 UTC, addresses: [#<Braintree::Address:0x007fe3639cefe8 @gateway=#<Braintree::Gateway:0x007fe364062eb8 @config=#<Braintree::Configuration:0x007fe3640630e8 @endpoint=nil, @environment=:sandbox, @public_key="vfyzr8zb7jqdhpxn", @private_key="[FILTERED]">>, @id="s7", @customer_id="person2359", @first_name=nil, @last_name=nil, @company=nil, @street_address="sdgfsgfgsdf", @extended_address=nil, @locality=nil, @region=nil, @postal_code=nil, @country_code_alpha2=nil, @country_code_alpha3=nil, @country_code_numeric=nil, @country_name=nil, @created_at=2014-04-29 15:57:32 UTC, @updated_at=2014-04-29 15:57:32 UTC>], credit_cards: [#<Braintree::CreditCard token: "66jz9r", billing_address: #<Braintree::Address:0x007fe3639cf8f8 @gateway=#<Braintree::Gateway:0x007fe364062eb8 @config=#<Braintree::Configuration:0x007fe3640630e8 @endpoint=nil, @environment=:sandbox, @public_key="vfyzr8zb7jqdhpxn", @private_key="[FILTERED]">>, @id="s7", @customer_id="person2359", @first_name=nil, @last_name=nil, @company=nil, @street_address="sdgfsgfgsdf", @extended_address=nil, @locality=nil, @region=nil, @postal_code=nil, @country_code_alpha2=nil, @country_code_alpha3=nil, @country_code_numeric=nil, @country_name=nil, @created_at=2014-04-29 15:57:32 UTC, @updated_at=2014-04-29 15:57:32 UTC>, bin: "411111", card_type: "Visa", cardholder_name: nil, created_at: 2014-04-29 15:57:32 UTC, customer_id: "person2359", expiration_month: "11", expiration_year: "2015", last_4: "1111", updated_at: 2014-04-29 15:57:32 UTC, prepaid: "Unknown", payroll: "Unknown", commercial: "Unknown", debit: "Unknown", durbin_regulated: "Unknown", healthcare: "Unknown", country_of_issuance: "Unknown", issuing_bank: "Unknown", image_url: "https://assets.braintreegateway.com/payment_method_logo/visa.png?environment=sandbox&merchant_id=b7gwpzqrspgmyc2x">]>> 
11:57:32 web.1 | Completed 500 Internal Server Error in 844ms 
11:57:32 web.1 | 
11:57:32 web.1 | NoMethodError (undefined method `credit_card_verification' for #<Braintree::SuccessfulResult:0x007fe3639ce4d0>): 
11:57:32 web.1 | app/controllers/payments_controller.rb:210:in `create_employer_account' 
11:57:32 web.1 | 
11:57:32 web.1 | 
11:57:32 web.1 | Rendered /usr/local/rvm/gems/[email protected]/gems/actionpack-4.0.0/lib/action_dispatch/middleware/templates/rescues/_source.erb (0.7ms) 
11:57:32 web.1 | Rendered /usr/local/rvm/gems/[email protected]/gems/actionpack-4.0.0/lib/action_dispatch/middleware/templates/rescues/_trace.erb (0.9ms) 
11:57:32 web.1 | Rendered /usr/local/rvm/gems/[email protected]/gems/actionpack-4.0.0/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (1.0ms) 
11:57:32 web.1 | Rendered /usr/local/rvm/gems/[email protected]/gems/actionpack-4.0.0/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb within rescues/layout (16.2ms) 

어떻게 내가 그렇게 검증 작업해야합니까 : 위의 코드에서 콘솔 로그 여기입니까?

+0

않으 셨습니다 @의 result' 발견 검증 문제를 나열'errors' 포함하고 있는지를'ErrorResult'이, 오른쪽이다 '것을 통지? –

+0

예, 부적절한 양식 제출과 관련된 오류 만 포함되어 있습니다. 누군가가 잘못된 숫자로 신용 카드 번호를 입력합니다. 양식이 올바르게 제출되었지만 어떤 이유에서 건 신용 카드가 거부되는 경우, braintree 사이트는 위에 사용 된 credit_card_verification 방법을 사용한다고 말합니다. 여기에 그 내용이 나와 있습니다 : https://www.braintreepayments.com/docs/ruby/card_verifications/overview. 양식에 적절한 정보가 입력 된 경우 서버 로그를 게시합니다.이 경우 여전히 작동하지 않습니다. – Philip7899

+0

난 그냥 – Philip7899

답변

1

Braintree는 전달 된 매개 변수가 유효한 경우에만 확인을 실행하고 실패한 경우 확인을 반환합니다.

첫 번째 예 (귀하의 게시물에서 편집 됨)에서 올바른 매개 변수를 전달하지 않았기 때문에 생성이 실패했습니다.

두 번째 예제에서는 확인이 성공하여 반환되지 않습니다.

는 잘못된 카드 번호 또는 Sandbox credit card numbers or unsuccessful verification numbers 중 하나를 사용하여 샌드 박스에서 서로 다른 조건을 시뮬레이션 할 수 있습니다.

예 :

result = Braintree::Customer.create( 
    :credit_card => {     
    :number => "4000111111111115",  
    :expiration_month => "10",   
    :expiration_year => "2014",  
    :cvv => "200",      
    :options => {:verify_card => true} 
    }         
)          

if result.success? 
    # handle success 
elsif result.credit_card_verification 
    p verification.processor_response_code 
    p verification.processor_response_text 
else 
    # use result.errors to see what part of the request was invalid 
+0

신난다, 고마워! 에스크로에있는 자금의 일부만을 어떻게 내야하는지, 아니면 내가 지원에 문의해야하는지에 대한 루비 문서가 어디에 있는지 알고 있습니까? – Philip7899

+0

@ Philip7899 에스크로우 된 거래에 대해서는 부분 환불이나 부분적 해지를 할 수 없습니다. – agf