How to add card holder's name to Stripe checkout using Elements?

前端 未结 4 1980
孤城傲影
孤城傲影 2021-02-04 00:43

I need to add an additional field to my custom form, I want to add the name of the credit card.

I tried in the following way:

var cardNameElement = eleme         


        
4条回答
  •  梦毁少年i
    2021-02-04 01:37

    As I struggled like an idoit on this for a while. As of Feb 2019 you can add tokenData object with information on the details of the card. For Example:

    let custData = {
                              name: 'Firstname Lastname',
                              address_line1: '21 Great Street',
                              address_line2: 'Shilloong',
                              address_city: 'Chicago',
                              address_state: 'Illinois',
                              address_zip: '12345',
                              address_country: 'US'
                  };
    
                  stripe.createToken(card, custData).then(function(result) {
                    if (result.error) {
                      // Inform the user if there was an error.
                      var errorElement = document.getElementById('card-errors');
                      errorElement.textContent = result.error.message;
                    } else {
                      // Send the token to your server.
                      stripeTokenHandler(result.token);
                    }
                  });
                });
    

提交回复
热议问题