2016-06-28 1 views
0

나는 많은 어려움을 겪어왔다. 어디서 잘못 될지 알 수 없다. 내가 믿을iOS와 Heroku 백엔드의 통합

https://github.com/stripe/example-ios-backend

:에서 사용 가능한 스트라이프의 예를 통해시나/루비 백엔드를 처리 애플 지불 요금 - 나는 상당히 신인입니다 만, 나는 응용 프로그램 개발자의 톤이 일상적으로 수행에 성공해야 뭔가를하려고

My Stripe 계정이 설정되어 있습니다. 테스트 모드에 있으며, 은행 확인을 완료했습니다. 모두 정상적으로 작동합니다.

Test API 키, 비밀 및 게시 가능을 사용하고 있습니다. 다음은 약간 수정 된 web.ry 파일의 코드입니다. 앱이 최소한 '/'끝점에서 작동하는 것을 볼 수 있습니다 : https://ibidurubypay.herokuapp.com - 제가 레일즈에서 무엇을하고 있는지 전혀 알지 못합니다. 제가 작성한 유일한 모델은 다음과 같습니다.

스트라이프 테스트 키를 삽입했습니다 변경 사항이 업데이트되고 있는지 확인하기 위해 초기 리턴 메시지를 약간 수정했습니다 Heroku가 나는 (스트라이프 계정 GBP입니다)

코드는 GBP에 통화를 변경 :

,536 나는에 'Stripe.xcworkspace'를 열고 https://github.com/stripe/stripe-ios/tree/master/Example

:에 당신은 루비 웹 응용 프로그램은

이 엑스 코드로 전환 ... 잘 실행 볼 수 있듯이, 그때 가서 스트라이프의 예를 다운로드
require 'sinatra' 
require 'stripe' 
require 'dotenv' 
require 'json' 

Dotenv.load 

Stripe.api_key = ENV['sk_test_mystripetestkeymystripetestkey'] 

get '/' do 
    status 200 
    return "Great, terrific, your backend is set up. Now you can configure the Stripe example iOS apps to point here." 
end 

post '/charge' do 

    # Get the credit card details submitted by the form 
    source = params[:source] || params[:stripe_token] || params[:stripeToken] 
    customer = params[:customer] 

    # Create the charge on Stripe's servers - this will charge the user's card 
    begin 
     charge = Stripe::Charge.create(
             :amount => params[:amount], # this number should be in cents 
             :currency => "gbp", 
             :customer => customer, 
             :source => source, 
             :description => "Example Charge" 
             ) 
             rescue Stripe::StripeError => e 
             status 402 
             return "Error creating charge: #{e.message}" 
    end 

    status 200 
    return "Charge successfully created" 

end 

get '/customers/:customer/cards' do 

    customer = params[:customer] 

    begin 
     # Retrieves the customer's cards 
     customer = Stripe::Customer.retrieve(customer) 
     rescue Stripe::StripeError => e 
     status 402 
     return "Error retrieving cards: #{e.message}" 
    end 

    status 200 
    content_type :json 
    cards = customer.sources.all(:object => "card") 
    selected_card = cards.find {|c| c.id == customer.default_source} 
    return { :cards => cards.data, selected_card: selected_card }.to_json 

end 

post '/customers/:customer/sources' do 

    source = params[:source] 
    customer = params[:customer] 

    # Adds the token to the customer's sources 
    begin 
     customer = Stripe::Customer.retrieve(customer) 
     customer.sources.create({:source => source}) 
     rescue Stripe::StripeError => e 
     status 402 
     return "Error adding token to customer: #{e.message}" 
    end 

    status 200 
    return "Successfully added source." 

end 

post '/customers/:customer/select_source' do 

    source = params[:source] 
    customer = params[:customer] 

    # Sets the customer's default source 
    begin 
     customer = Stripe::Customer.retrieve(customer) 
     customer.default_source = source 
     customer.save 
     rescue Stripe::StripeError => e 
     status 402 
     return "Error selecting default source: #{e.message}" 
    end 

    status 200 
    return "Successfully selected default source." 

end 

delete '/customers/:customer/cards/:card' do 

    card = params[:card] 
    customer = params[:customer] 

    # Deletes the source from the customer 
    begin 
     customer = Stripe::Customer.retrieve(customer) 
     customer.sources.retrieve(card).delete() 
     rescue Stripe::StripeError => e 
     status 402 
     return "Error deleting card" 
    end 

    status 200 
    return "Successfully deleted card." 

end 

앱 'stripe-ios-master'폴더에 있습니다. 내 애플 개발자 계정에서

, 나는 내가 ApplePay을 쳤다 새로운 응용 프로그램 'com.AH.thenameigaveit'상인

을 설정하고 다음으로 상인 식별자를 설정 이동 merchant.com.AH.thenameigaveit

스트라이프로 이동하여 CSR 인증서를 작성한 다음 Apple Dev의 판매자 ID와 연결합니다.

새로운 Apple CER 파일을 가져 와서 Stripe에 업로드했는데 성공적으로 설치되었는지 확인할 수있었습니다.

Xcode로 돌아 가기 프로비저닝 프로파일 문제에 대해 픽스 이슈가 발생했으며 모두 받아들입니다.

내 자격 파일은 말한다 'com.apple.developer.in - 앱 결제'

지금 엑스 코드에서 나는 스트라이프의 '간단한'예에 ViewController.swift로 이동으로 다양한 사용자 변수의 값을 변경

다음 :

stripePublishableKey = " 'pk_test_mystripetestkeymystripetestkey'"키 게시 가능한 내 테스트

backendChargeURLString = "https://ibidurubypay.herokuapp.com"

appleMerchantId = "merchant.com .AH.thenameigaveit "

스트라이프의 '간단한'예제에 유의하십시오. 스위프트 코드는 USD와 통화를 내 웹과 비교하는 것입니다.ry 스크립트는 "gbp"를 가리 킵니다. 그러나 과거에 두 번 시도했을 때 말할 수있는 것에서 보면 통화 값이 Ruby 스크립트에 전달되지 않아서 문제가 아닌 것처럼 보입니다 (그리고 내 스트라이프 계정은 GBP입니다.) 그래서

, 라이브 비자 신용 카드로 활성화 지불한다 아이폰 6에 플러스 애플 구축하고 실행하는 데 시간이 ... 응용 프로그램이 성공적으로 처음 빌드 ..

처음 주위에 "지불 요청이 유효하지 않습니다 : 자격을 확인하십시오"라는 메시지가 표시되므로 Capabilities로 가서 ApplePay에 대해 올바른 판매자 ID를 확인하십시오. 다시 빌드하고 이번에는 Apple Pay 화면이 완벽하게 나타납니다. 스크린, 멋진 셔츠에 대해 10 달러를 지불하기 위해 Apple Pay 연결된 신용 카드를 지정. uch, 'Payment Not Completed!'직후 'Processing Payment'가 나오고 Apple Pay 대화 상자가 '셔츠를 사기'옵션으로 돌아가는 화면으로 돌아갑니다.

그래서 나는 절대적으로 아무것도 아는 것이 없습니다. 내가 삽입을 시도하고 다시 호출에서 오는 약간의 정보를 수집합니다를 제외하고 본 서버 백엔드와 통신에 대한, 그래서 :

print ("data: \(data), \r\r response: \(response), \r\r error: \(error)") 

저를 제공합니다

카드 거부 메시지로 나타납니다

data: Optional(),

response: Optional({ URL: *(ASBEFORE)*ibidurubypay.herokuapp.com/charge } { status code: 402, headers { Connection = "keep-alive"; "Content-Length" = 248; "Content-Type" = "text/html;charset=utf-8"; Date = "Tue, 28 Jun 2016 00:16:43 GMT"; Server = "WEBrick/1.3.1 (Ruby/2.1.2/2014-05-08)"; Via = "1.1 vegur"; "X-Content-Type-Options" = nosniff; "X-Frame-Options" = SAMEORIGIN; "X-Xss-Protection" = "1; mode=block"; } }),

error: nil

, 하지만 카드에는 아무런 문제가 없습니다. 포털에서 내 스트라이프 계정에

은 토큰이 성공적으로시 생성 : 2016년 6월 28일 1시 16분 42초를

... 그러나, 나는 어디서든 볼 수있는 402 감소의 증거는 없다 여기, 어쩌면 나는 올바른 곳을보고 있지 않다 ...

누군가가 나에게 무슨 일이 일어나고 있는지 알 수 있다면 정말 고마워 할 것이다. 나는 머리카락을 찢어 내고있다.

+1

Ruby를 처음 접했을 때'byebug'에 대해 조금 읽고 디버깅을 할 때 사용하는 것이 좋습니다. 컨트롤러 동작에 중단 점을 배치하고 올바른 매개 변수가 클라이언트에서 전송되는지 확인할 수 있습니다. 또한 irb에서'Stripe :: Charge.create' 호출을 테스트 한 후에 프론트 엔드에 연결하십시오. 진정한 오류의 범인을 식별하기 위해 격리 된 코드 조각을 테스트하는 데 도움이됩니다. –

답변

0
확인

, 그래서 스트라이프에서이 질문을 사람을 물어 그들이 똑바로 그것을 해결을 통해 저를 불어했다 - 문제가 있었다 :

Stripe.api_key = ENV 내 루비 스크립트 [ 'sk_test_mystripetestkeymystripetestkey']

.. .

중 하나는 같아야

Stripe.api_key = 'sk_test_mystripetestkeymystripetestkey'

OR (더 ENV [] 보충 없음) : BETTER : 그것은 원래 스트라이프에서 다운로드로 할 필요가있는 경우, 환경을 변하기 쉬운

다음과 같은 테스트 API 키를 STRIPE_TEST_SECRET_KEY라는 이름의 환경 변수를 만들려면 Heroku가 구성을 업데이트

Stripe.api_key = ENV [ 'STRIPE_TEST_SECRET_KEY'] : 스크립트, 그래서 나는 그 때, 스트라이프에서 설정하는 값 : https://devcenter.heroku.com/articles/config-vars

한 번 당신이 알고있는 방법으로 일단 파이, 큰 지원을위한 Stripe!