条纹获取输入的邮政编码

时间:2019-03-13 13:02:33

标签: stripe-payments

我正在使用Stripe PaymentIntents,并且在使用handleCardPayment()时需要获取输入的邮政编码/邮政编码,任何人都知道获取此信息的方法,所以我可以只保存邮政编码?

cardButton.addEventListener('click', function (ev) {
ev.preventDefault();
stripe.handleCardPayment(
    clientSecret, cardElement, {
        source_data: {
            owner: {
                name: cardholderName.value,
                address: {
                    line1: cardholderAddress,
                    line2: cardholderAddress2,
                    city: cardholderTown,
                    county: cardholderCounty
                },
                email: cardholderEmail,
                phone: cardholderTel
            }
        }
    }
).then(function (result) {
    if (result.error) {
        // Display error.message in your UI.
        //alert("NO!!!!!!!!!!")
        var errorElement = document.getElementById('payment-errors');
        errorElement.textContent = result.error.message;
    } else {
        // The payment has succeeded. Display a success message.

        var form = document.getElementById('payment-form');

        // Submit the form
        form.submit();
    }
});

1 个答案:

答案 0 :(得分:0)

万一其他人需要它,我可以在服务器端使用karllekko的建议来实现:

客户侧

stripe.handleCardPayment(
    clientSecret, cardElement, {
        source_data: {
            owner: {
                name: cardholderName.value,
                address: {
                    line1: cardholderAddress,
                    line2: cardholderAddress2,
                    city: cardholderTown,
                    county: cardholderCounty
                },
                email: cardholderEmail,
                phone: cardholderTel
            }
        }
    }
).then(function (result) {
    if (result.error) {
        // Display error.message in your UI.
        var errorElement = document.getElementById('payment-errors');
        errorElement.textContent = result.error.message;
    } else {
        // The payment has succeeded. Display a success message.

        var form = document.getElementById('payment-form');

        var hiddenInput = document.createElement('input');
        hiddenInput.setAttribute('type', 'hidden');
        hiddenInput.setAttribute('name', 'srcId');
        hiddenInput.setAttribute('value', result.paymentIntent.source);
        form.appendChild(hiddenInput);

        // Submit the form
        form.submit();
    }
});

服务器端

[HttpPost]
public ActionResult BookingPaymentForm(FormCollection formData, PaymentEventModel model)
{
    model.SourceId = formData["srcId"];
    var service = new SourceService();
    var source = service.Get(model.SourceId);
    var postcode = source.Owner.Address.PostalCode;
}