Rails4 Koudoku Gem Getting Error : Uncaught Error: You are using a secret key with Stripe.js, instead of the publishable one
Rails4 Koudoku Gem Getting Error : Uncaught Error: You are using a secret key with Stripe.js, instead of the publishable one
我一直在尝试将 Koudoku gem 集成到我们将订阅的应用程序之一。我已经开始使用 gem 提供的构建器,并相应地自定义了视图。问题是,我一直收到这个错误(客户端,javascript)-
"Uncaught Error: You are using a secret key with Stripe.js, instead of the publishable one."
虽然我已经把它放在例子中了;
Stripe.setPublishableKey("#{Koudoku.stripe_publishable_key}");
我按照示例中给出的相同过程进行操作,上面是我通过 javascript 得到的错误。下面是我在 form-post;
之后得到的错误
The provided key 'pk_test_************************' does not have the
required permissions for this endpoint on account
'acct_****************'. Having more permission would allow this
request to continue.
任何人都可以指导我解决这个错误。
这是来自 _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;
});
});
提前致谢。
尼尚特
您的错误涉及您的 javascript 说您使用的是秘密密钥,而您的 ruby 说您使用的是可发布的密钥,所以我假设您将它们倒置在哪里曾经你设置 #{Koudoku.stripe_publishable_key}"
。 #{Koudoku.stripe_publishable_key}"
应该是 pk_test_...
我一直在尝试将 Koudoku gem 集成到我们将订阅的应用程序之一。我已经开始使用 gem 提供的构建器,并相应地自定义了视图。问题是,我一直收到这个错误(客户端,javascript)-
"Uncaught Error: You are using a secret key with Stripe.js, instead of the publishable one." 虽然我已经把它放在例子中了;
Stripe.setPublishableKey("#{Koudoku.stripe_publishable_key}");
我按照示例中给出的相同过程进行操作,上面是我通过 javascript 得到的错误。下面是我在 form-post;
之后得到的错误The provided key 'pk_test_************************' does not have the required permissions for this endpoint on account 'acct_****************'. Having more permission would allow this request to continue.
任何人都可以指导我解决这个错误。
这是来自 _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;
});
});
提前致谢。 尼尚特
您的错误涉及您的 javascript 说您使用的是秘密密钥,而您的 ruby 说您使用的是可发布的密钥,所以我假设您将它们倒置在哪里曾经你设置 #{Koudoku.stripe_publishable_key}"
。 #{Koudoku.stripe_publishable_key}"
应该是 pk_test_...