更新: 設置您的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"
}
但該應用程序仍然拋出沒有鍵的錯誤。希望這有助於?
當你找到自己問題的答案時,你被允許並被鼓勵將其添加爲正式答案。而且,如果你自己的答案是最好的答案,你可以授予它複選標記。您可以(也應該,我認爲)編輯您的問題,刪除頂部的答案,並將其添加爲常規...以及答案。 –