我一直在尝试将Koudoku gem集成到我们将要订阅的App中。我已经开始使用gem提供的构建器,并相应地自定义视图。问题是,我一直在收到此错误(客户端,javascript) -
"未捕获错误:您正在使用Stripe.js的密钥,而不是可发布的密钥。" 虽然我在例子中说它就像它那样;
Stripe.setPublishableKey("#{Koudoku.stripe_publishable_key}");
我遵循了示例中给出的相同过程,上面是我通过javascript获得的错误。以下是我在形式发布后得到的错误;
提供的密钥' pk_test _ ************************'没有 帐户上此端点所需的权限 ' ACCT _ ****************&#39 ;.获得更多许可将允许这样做 请求继续。
请有人请指导我完成此错误。
这是来自_card.html.slim
的整个html
- content_for :koudoku do
script type="text/javascript" src="https://js.stripe.com/v2/"
= form_for @subscription, url: url, html: {id: 'payment-form', class: 'form-horizontal'} do |f|
.form-group
label Card Number
.input-icon-wrapper
input type="text" class="form-control card-number" autocomplete="off" size="20"
.form-group
label Expiration (MM-YYYY)
.input-icon-wrapper
.col-sm-3
input type="text" class="form-control card-expiry-month" size="2"
.col-sm-1
span
| -
.col-sm-3
input type="text" class="form-control card-expiry-year" size="4"
.form-group
label CVC
.input-icon-wrapper
input type="text" class="form-control card-cvc" autocomplete="off" size="4"
.alert.alert-error.payment-errors
= f.hidden_field :plan_id
.control-group
.controls
- if Koudoku.free_trial?
button type="submit" class="btn btn-primary submit-button"
| Save Billing Information
- else
button type="submit" class="btn btn-primary submit-button"
| Upgrade Your Account
= link_to "Cancel", owner_subscriptions_path(@owner), class: 'btn'
javascript:
// All this code taken from Stripe's own examples at:
// https://stripe.com/docs/tutorials/forms .
function stripeResponseHandler(status, response) {
console.log(">>>> Inside stripeResponseHandler | Status : ", status, " | Response : ", 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");
console.log(">>>> card-number : ", $('.card-number').val(), " | card-cvc : ", $('.card-cvc').val(), " | card-expiry-month : ", $('.card-expiry-month').val(), " | card-expiry-year : ", $('.card-expiry-year').val());
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;
});
});
&#13;
提前致谢。 NISHANT
答案 0 :(得分:1)
你的错误涉及你的javascript说你正在使用一个密钥,并且你的红宝石说你正在使用一个可发布的密钥,所以我假设你把它们放在你设置#{Koudoku.stripe_publishable_key}"
的地方。 #{Koudoku.stripe_publishable_key}"
应该是pk_test_...