gpt4 book ai didi

javascript - Stripe JavaScript 在 Rails 4 的测试模式下显示实时模式

转载 作者:行者123 更新时间:2023-11-30 00:10:38 25 4
gpt4 key购买 nike

正如您从下面的附件中看到的那样,我在测试模式下运行,当我尝试使用 testing stripe cards 时特别是 4242424242424242 没有任何效果。我该如何调试?

Stripe 错误的控制台日志:

enter image description here

Stripe 界面:

enter image description here

正在进行的 JavaScript 代码:

    function process_payment(cardNumber, cardExpiration, cardVerification, zipCode, price){
var vpf = validate_payment_fields();
if(vpf === true){
process_stripe_api(cardNumber, cardExpiration, cardVerification, zipCode, price);
// $contentLoader.show();
// clear_cc_fields($cardNumber, $cardExpiration, $cardVerification, $zipCode);
// $paymentProcessorForm.submit();
}
}

function process_stripe_api(cardNumber, cardExpiration, cardVerification, zipCode, price){
Stripe.createToken({
number: cardNumber,
cvc: cardVerification,
exp_month: cardExpiration.substring(0,2),
exp_year: cardExpiration.substring(3,5),
price: price
}, stripeResponseHandler);
}

function stripeResponseHandler(status, response) {
if (response.error) {
debugger;
}
else {
console.log('passed!');
debugger;
}
}

function validate_payment_fields(){
var $cardNumber = jQuery('#card_number');
var $cardVerification = jQuery('#card_verification');
var $cardExpiration = jQuery('#card_expiration');
var $zipCode = jQuery('#zip_code');

$cardNumber.next('.help-error').remove();
$cardVerification.next('.help-error').remove();
$cardExpiration.next('.help-error').remove();
$zipCode.next('.help-error').remove();

trim_field($cardNumber);
var cardNumber = validate_card_number($cardNumber);

trim_field($cardExpiration);
var cardExpiration = validate_card_expiration($cardExpiration);

trim_field($cardVerification);
var cardVerification = validate_card_verification($cardVerification);

trim_field($zipCode);
var zipCode = validate_zipcode($zipCode);

if(cardNumber && cardExpiration && cardVerification && zipCode){
return true;
}
else{
return false;
}
}

function clear_cc_fields(cardNumber, cardExpiration, cardVerification, zipCode){
cardNumber.val('');
cardVerification.val('');
cardExpiration.val('');
zipCode.val('');
}

function validate_card_number(field){
var regTester = new RegExp("\\d{16}");
if(regTester.test(field.val())){
return true;
}
else{
field.after("<p class='help-error'>Credit Card Number is Invalid!</p>");
return false;
}
}

function validate_card_expiration(field){
var regTester = new RegExp("^((0[1-9])|(1[0-2]))\/((2009)|(20[1-2][0-9]))$");
if(regTester.test(field.val())){
return true;
}
else{
field.after("<p class='help-error'>Credit Card Expiration is Invalid!</p>");
return false;
}
}

function validate_card_verification(field){
var regTester = new RegExp("\\d{3}");
if(regTester.test(field.val())){
return true;
}
else{
field.after("<p class='help-error'>CCV is Invalid!</p>");
return false;
}
}

function validate_zipcode(field){
var regTester = new RegExp("\\d{5}");
if(regTester.test(field.val())){
return true;
}
else{
field.after("<p class='help-error'>Zip Code is Invalid!</p>");
return false;
}
}

function trim_field(field){
var tmp = jQuery.trim(field.val());
field.val(tmp);
return tmp;
}

View 中的一个片段:

= javascript_include_tag 'https://js.stripe.com/v2/'

javascript:
Stripe.setPublishableKey("#{ENV['MY_STRIPE_PUBLISHABLE_KEY']}");

形式:

enter image description here

最佳答案

确保您使用的 Stripe key 是测试 key 而不是生产 key :

enter image description here

您的 key 应以 pk_testsk_test 开头

关于javascript - Stripe JavaScript 在 Rails 4 的测试模式下显示实时模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36661302/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com