更新: 设置您的API密钥我设置可发布密钥直接内联像这样:Stripe.setPublishableKey("pk_live_*****");
它的工作原理! 问题是它没有正确配置与ENV['stripe_publishable_key']
。Stripe :: AuthenticationError没有提供API密钥。使用“Stripe.api_key = <API-KEY>”
原贴:
我使用了条纹koudoku宝石。一切工作正常当地,但是当我推到Heroku的,我得到的错误:虽然
Stripe::AuthenticationError (No API key provided. Set your API key using "Stripe.api_key = <API-KEY>".
它设置在发展中的重点可发布。另外,如果我运行heroku config,我会在那里看到钥匙。
这里发生了什么?为什么不设置密钥?
application.yml
development:
stripe_api_key: 'sk_test_***'
stripe_publishable_key: 'pk_test_***'
production:
stripe_api_key: 'sk_live_***'
stripe_publishable_key: 'pk_live_***'
配置/初始化/ koudoku.rb
Koudoku.setup do |config|
config.subscriptions_owned_by = :user
config.stripe_publishable_key = ENV['stripe_publishable_key']
config.stripe_secret_key = ENV['stripe_api_key']
Stripe.api_version = '2015-01-11' #Making sure the API version used is compatible.
# config.prorate = false # Default is true, set to false to disable prorating subscriptions
# config.free_trial_length = 30
# Specify layout you want to use for the subscription pages, default is application
config.layout = 'application'
# you can subscribe to additional webhooks here
# we use stripe_event under the hood and you can subscribe using the
# stripe_event syntax on the config object:
# config.subscribe 'charge.failed', Koudoku::ChargeFailed
end
_card.html.erb
<div class="padding_page">
<div class="wrapper_form_dark wrapper_form_sign_on">
<%# content_for :koudoku do %>
<%# end %>
<%= form_for @subscription, url: url, html: {id: 'payment-form', class: 'form-horizontal'} do |f| %>
<fieldset>
<div class="form_section">
<legend class="page_title">Update Payment Info</legend>
<label class="label_standard">Card Number</label>
<div class="controls">
<input type="text" size="20" autocomplete="off" class="card-number input_standard"/>
</div>
</div>
<div class="form_section">
<label class="label_standard">Expiration (MM/YYYY)</label>
<div class="controls">
<input type="text" size="2" class="card-expiry-month input_mini"/>
<span>/</span>
<input type="text" size="4" class="card-expiry-year input_mini"/>
</div>
</div>
<div class="form_section">
<label class="label_standard">CVC</label>
<div class="controls">
<input type="text" size="4" autocomplete="off" class="card-cvc input_mini"/>
</div>
</div>
<div class="alert alert-error payment-errors red"></div>
<%= f.hidden_field :plan_id %>
</fieldset>
<div class="form_section">
<div class="actions">
<% if Koudoku.free_trial? %>
<button type="submit" class="btn_primary submit-button">Save Billing Information</button>
<% else %>
<button type="submit" class="btn_primary_large submit-button">Update Card Information</button>
<% end %>
<%= link_to "Cancel", owner_subscriptions_path(@owner), class: 'btn red' %>
</div>
</div>
<% end %>
</div>
</div>
<script type="text/javascript">
// All this code taken from Stripe's own examples at:
// https://stripe.com/docs/tutorials/forms .
function stripeResponseHandler(status, response) {
if (response.error) {
// show the errors on the form
$(".payment-errors").text(response.error.message).show();
$(".submit-button").removeAttr("disabled");
} else {
var form$ = $("#payment-form");
// token contains id, last4, and card type
// insert the token into the form so it gets submitted to the server
form$.append("<input type='hidden' name='subscription[credit_card_token]' value='" + response['id'] + "'/>");
form$.append("<input type='hidden' name='subscription[last_four]' value='" + response['last4'] + "'/>");
form$.append("<input type='hidden' name='subscription[card_type]' value='" + response['card_type'] + "'/>");
// and submit
form$.get(0).submit();
}
}
$(document).ready(function() {
Stripe.setPublishableKey("<%= Koudoku.stripe_publishable_key %>");
// By default, don't show errors.
$(".payment-errors").hide()
$("#payment-form").submit(function(event) {
// disable the submit button to prevent repeated clicks
$('.submit-button').attr("disabled", "disabled");
Stripe.createToken({
number: $('.card-number').val(),
cvc: $('.card-cvc').val(),
exp_month: $('.card-expiry-month').val(),
exp_year: $('.card-expiry-year').val()
}, stripeResponseHandler);
// prevent the form from submitting with the default action
return false;
});
});
</script>
更新: 我看到帖子的日志在条纹的日志中,它的响应为200 ...
{
"card": {
"number": "************5458",
"cvc": "***",
"exp_month": "11",
"exp_year": "2019"
},
"key": "pk_live_***",
"payment_user_agent": "stripe.js/81eca10",
"callback": "sjsonp1484600040115",
"_method": "POST",
"_accept_language": "en-US"
}
但该应用程序仍然抛出没有键的错误。希望这有助于?
当你找到自己问题的答案时,你被允许并被鼓励将其添加为正式答案。而且,如果你自己的答案是最好的答案,你可以授予它复选标记。您可以(也应该,我认为)编辑您的问题,删除顶部的答案,并将其添加为常规...以及答案。 –