2016-06-28 58 views
0

我一直有很多困难与此,我只是不能看到我要去哪里错了。虽然我很菜鸟,我试图做一些事情一吨的应用程序开发者必须做例行成功 - 过程苹果支付费用,通过条纹的例子西纳特拉/ Ruby的后端可在:iOS与Heroku后端集成

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

我相信我已经做好了一切:

我的条纹帐户设置,我处于测试模式,我已验证我的银行,这一切都很好。

我正在使用测试API密钥,秘密并可发布:以下是我稍微修改过的web.ry文件中的代码:如果您转到:https://ibidurubypay.herokuapp.com,您可以看到该应用至少在'/'端点工作 - 请注意我绝对没有想法我在Rails中做了什么 - 我做的唯一mod是:

我已经插入了条纹测试键 我稍微修改了初始返回消息来检查正在更新的更改Heroku 我将货币更改为GBP(条纹账户为GBP)

代码是:

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 

正如你可以看到Ruby的web应用程序运行良好......

切换到Xcode中,我则去下载条纹的例子Apps的:https://github.com/stripe/stripe-ios/tree/master/Example

我在打开“Stripe.xcworkspace” 'stripe-ios-master'文件夹。

在我的苹果开发者帐户,我去建立一个新的应用程序“com.AH.thenameigaveit”商人

我打勾ApplePay,然后建立一个商户标识具有:merchant.com.AH.thenameigaveit

我去Stripe并创建一个CSR证书,然后在Apple Dev中与我的商家ID进行链接。

我得到了我的新Apple CER文件并将其上传到Stripe - 我能够验证它是否已成功安装。

回到Xcode我打开修复问题供应配置文件的问题,它都被接受。

我的权利的档案上写着“com.apple.developer.in应用程序内支付”

现在在Xcode我去ViewController.swift在条纹的“简单”例如,改变各种用户变量的值如下:

stripePublishableKey =“ 'pk_test_mystripetestkeymystripetestkey'”我的测试发布的关键

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

appleMerchantId =“merchant.com .AH.thenameigaveit“

请注意条纹”简单“示例Swift代码是指货币为USD而我的网络。ry脚本指的是“gbp”,但是从我以前可以告诉我的情况来看,当我每次尝试它几次时,它看起来应该不重要,因为货币值不会传递给Ruby脚本(并且我的条纹帐户英镑)。

所以,时间来建立和运行一个iPhone 6加上苹果上付费激活与现场签证信用卡...应用构建成功第一次..

第一次围绕它说:“付款请求无效:检查你的权利”,所以我去能力,并确保正确的商家ID与ApplePay检查 - 再次建立,这次我们得到进一步 - Apple Pay屏幕上完美屏幕,指定Apple Pay链接的信用卡支付10美元的凉爽衬衫.. - 我做的然后,在'付款未完成'后不久,它出现'处理付款',然后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”在我的Ruby脚本.. 。

之一:它应该是:

Stripe.api_key = 'sk_test_mystripetestkeymystripetestkey'(注意没有ENV [])

OR:更多:如果应该,因为它最初是从条纹下载环境变量,然后我成立于条纹,所以在脚本:

Stripe.api_key = ENV [“STRIPE_TEST_SECRET_KEY”]

然后更新您的Heroku的配置创建一个名为STRIPE_TEST_SECRET_KEY与测试的API密钥作为环境变量价值:https://devcenter.heroku.com/articles/config-vars

一旦你知道怎么做就像馅饼一样,谢谢大家的支持!