简体   繁体   中英

Get paymentIntentSecret to Javascript with httppost

That's how my problem is when I need to httppost something. then i want to receive subscription.LatestInvoice.PaymentIntent.ClientSecret value over to my js file.

When I click pay then strip must specify an subscription.LatestInvoice.PaymentIntent.ClientSecret value for my js file.

But it never comes out.

However, Stripe informs me:

Uncaught IntegrationError: Invalid value for stripe.handleCardPayment intent secret: value should be a client secret of the form ${id} secret ${secret}. You specified: .

My httppost - Controller:

[HttpPost]
    [Route("Members/AddMembership/{id}/{CompaniesId}")]
    public async Task<IActionResult> AddMembership(MembersView model)
    {
        try
        {

            //Here before that comes some strip code and everything else ...
            model.PiinVoice = subscription.LatestInvoice.PaymentIntent.ClientSecret;


            return View(model);
        }
        catch(Exception e)
        {
            TempData[TempDataClass.Error] = true;
            TempData[TempDataClass.ErrorMsg] = HelperText.ExceptionError + e.Message;
            return RedirectToAction("", "User");
        }
    }

I got the js code via Stripe which is on this link .

My javascript here.

.... more here....
//I Need value from this one.
var paymentIntentSecret = document.getElementById('PiinVoice').value;  


// Handle form submission.
var form = document.getElementById('payment-form');
    form.addEventListener('submit', function (event) {   
    event.preventDefault();

    stripe.handleCardPayment(paymentIntentSecret).then(function(result) {
      if (result.error) {
        // Display error.message in your UI.
          // Inform the user if there was an error.
          var errorElement = document.getElementById('card-errors');
          errorElement.textContent = result.error.message;
      } else {
        // The payment has succeeded. Display a success message.
          stripeTokenHandler(result.token);
      }
    });
});
.... more here...

What I would like to hear about it is possible to do so that subscription.LatestInvoice.PaymentIntent.ClientSecret is thrown into my PiinVoice. It is in relation to 3D Secure that it can be implemented.

Against if I run the old code before 3d. and paid and then went in and found the invoice id and thrown in at var paymentIntentSecret = "xxxxxxx" then it works fine.

Have you tried printing subscription.LatestInvoice.PaymentIntent.ClientSecret in the backend code to investigate this? Since it seems to be null.

That could happen if you didn't expand that field when creating the subscription like the docs recommend. https://stripe.com/docs/billing/subscriptions/payment#signup-4

var options = new SubscriptionCreateOptions
{
    CustomerId = customer.Id,
    Items = items,
    Expand = new List<string>() { "latest_invoice.payment_intent" }
};

var subscriptionServices = new SubscriptionService();
Subscription subscription = subscriptionServices.Create(options);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM