You are trying to implement a custom form for Pay.jp.
I get various values from the form and createToken, but I can't get the token because it's Invalid expiration year.The code is as follows:
$(function(){
$('#checkout_form_payment').submit(function(){
varcard, cvc, exp_month, exp_year, expire, number;
number = $('#card_number') .val();
cvc=$('#card_code').val();
expire=$('#card_expiry').val();
exp_month=expire.substr(0,2);
exp_year=expire.substr(5,2);
card = {
number —Number,
cvc —cvc,
exp_month —exp_month,
exp_year —exp_year
};
alert(JSON.stringify(card));
Payjp.createToken(card, function(s, response){
vartoken;
if(response.error){
alert(response.error.message);
return false;
} else{
alert("res="+response.id);
token=response.id;
$('#checkout_form_payment') .append($('<input type="hidden" name="payjpToken"/>').val(token));
$('#checkout_form_payment').submit();
}
return
The following values are entered:
number='42424242424242424242';
cvc = '123';
expire='12/20';
So exp_year is 20.Where is the problem?
Just in case, the sauce of the form is long, so I'll omit it.I have checked to the point where each value is obtained.
According to this API reference Token(Token), the expiration year information appears to be 4 digits A.D.
Try adding "20" to your head.
Example in curl
curl https://api.pay.jp/v1/tokens\
-usk_test_c62fade9d045b54cd76d7036:\
- H "X-Payjp-Direct-Token-Generate: true" \
-d" card [number] = 424242424242424242" \
-d"card[cvc]=123"\
-d"card[exp_month]=02"\
-d "card [exp_year] = 2020"
Example in Node
var payjp=require('payjp')('sk_test_c62fade9d045b54cd76d7036');
payjp.tokens.create(
query = {
card: {
number —424242424242424242,
cvc:123,
exp_month —2,
exp_year: 2020
},
},
headers = {
'X-Payjp-Direct-Token-Generate': 'true'
}
);
© 2024 OneMinuteCode. All rights reserved.