#mnord

1 messages ยท Page 1 of 1 (latest)

acoustic peakBOT
inland fulcrum
#

Hi! Let me help you with this.

winter yacht
#

Do I need to add anything to this code? var options = new PaymentIntentCreateOptions
{
Amount = Convert.ToInt64(Convert.ToDecimal(hdnTotal.Value) * 100),
Currency = "usd",
PaymentMethodTypes = new List<string> { "card" },
Metadata = new Dictionary<string, string> { { "userID", userID.ToString() } }
};

inland fulcrum
#

The PaymentIntent is not directly an alternative for Card Element.
Have you changed your frontend component or your backend integration?

winter yacht
#

Yes

inland fulcrum
#

Have you changed your frontend component or your backend integration? ๐Ÿ™‚

winter yacht
#

Both

#

Do I have to create a PaymentMethodOptions? If so, I saw that it gets the credit card info. How would I retrieve this info if it is needed?

inland fulcrum
winter yacht
#

I am using WebForms not MVC. So, do I just need to add AutomaticPaymentMethods to make it work?

novel raptor
#

How are you collecting payment information from your customers? That's the missing component here

winter yacht
#

I am using the following: var options = new PaymentIntentCreateOptions
{
Amount = Convert.ToInt64(Convert.ToDecimal(hdnTotal.Value) * 100),
Currency = "usd",
AutomaticPaymentMethods = new PaymentIntentAutomaticPaymentMethodsOptions
{
Enabled = true,
},
Metadata = new Dictionary<string, string> { { "userID", userID.ToString() } }
};

#

Is there a way to turn off the Autofill with Card Lin k?

novel raptor
winter yacht
#

In my webhook, I am using: var endpointSecret = ConfigurationManager.AppSettings["endpointSecret"].ToString();
var json = new StreamReader(context.Request.InputStream).ReadToEnd();
var signature = context.Request.Headers["Stripe-Signature"];

  try
  {
    var stripeEvent = EventUtility.ConstructEvent(
        json,
        context.Request.Headers["Stripe-Signature"],
        endpointSecret
    );

    switch (stripeEvent.Type)
    {
      case Events.PaymentIntentSucceeded:
        var paymentIntent = stripeEvent.Data.Object as PaymentIntent;
        Dictionary<string, string> dict = paymentIntent.Metadata;
        long userID = Convert.ToInt64(dict["userID"]);

        CartDAL.UpdateCartToDB(userID);
        string filePath = context.Server.MapPath("~/");
        PDFHelper.CreateReceipt(userID, filePath);
        CartDAL.DeleteCart(userID);
        break;
      default:
        break;
    }
#

Is there more to processing a payment than the above code?

#

On the Javascript side, I have: var elements = stripe.elements({ clientSecret: strClientSecret, appearance});
const paymentElement = elements.create("payment");
paymentElement.mount("#payment-element");

  // when the form is submitted...
  var form = document.getElementById("frmPayOrder");
  form.addEventListener("submit", function (e) {
    e.preventDefault();

    // tokenize payment details and confirm the payment intent
    stripe.confirmPayment({
      elements,
      confirmParams: {
        return_url: 'OrderSuccess.aspx',
      },
      redirect: 'if_required',
    });
  });
novel raptor
#

Ok, and is the Payment Element mounted in your frontend application?

winter yacht
#

See above code

novel raptor
#

I see the code. Is it working is the question?

#

Have you tried completing the form with test data and completing the payment?

winter yacht
#

I am still getting an error that I have entered payent method.

#

have not

#

I am getting error that I have not entered payment method.

novel raptor
#

When do you get that error?

winter yacht
#

But, I set the PaymentIntent like so:

#

AutomaticPaymentMethods = new PaymentIntentAutomaticPaymentMethodsOptions
{
Enabled = true,
},

#

I get the error in the Dashboard when it creates the PaymentIntent.

#

I am getting a server post of 200 for the PaymentIntent created but it gives an error of Incomplete in the dashboard.

novel raptor
#

What is your understanding of the automatic payment methods parameter?

winter yacht
#

very little

novel raptor
#

It doesn't work like you expect it to it seems

winter yacht
#

I had specified payment method of card but it still said I didn't have a payment method specified.

novel raptor
#

It's for calculating which payment method types (i.e. card, bank debits, etc) will be shown to your customers in the Payment Element

winter yacht
#

ok

#

I just want cards only

novel raptor
winter yacht
#

I am using WebForms not MVC.

novel raptor
#

Seems you're missing the part where you return the PI your backend creates to your front-end to initialise the Payment Element, in order to collect payment details and confirm.

novel raptor
winter yacht
#

I only need to know how to correctly specifiy the payment method in the PaymentIntent.

novel raptor
#

That's the data you need to collect from your customers in the Payment Element

winter yacht
#

But, we don't have access to the text boxes that Stripe generates in the payment element.

novel raptor
#

Then how are you expecting to collect payment information from your users in a PCI compliant manner?

winter yacht
#

Do you know how to specify the payment method in the PaymentIntent? Thats what I need.

#

If you don't know, can someone else help me?

novel raptor
#

But not really sure how that'll help you build an integration unless you've previously collected payment info and created a Payment Method object

winter yacht
#

I have not created a Payment Method object. When I look at the documentation, it shows that a Payment Method contains the credit card number, expire date, cvc, etc. I don't know how to collect that from the Stripe text boxes that are generated in the Payment Element. The documentation doesn't cover that well. So, do I need to focus on trying to figure out how to create a Payment Method? I thought that there was a way to default to cards?

#

I really don't want to collect the customer's address. Do you have to collect this info to create a Payment Method?

novel raptor
#

I don't know how to collect that from the Stripe text boxes that are generated in the Payment Element
The confirmPayment method takes care of that for you. When you initialise the Payment Element, your users input their data and click submit. The button will have an click handler to trigger confirmPayment, which will tokenise the payment info from the Element into a Payment Method object and attempt to confirm the payment with those details. There's no need for you to collect the data from the form, by doing that you'd forgo the PCI compliance you inherit by proxy of using Stripe Elements.

winter yacht
#

ok. It sounds like the missing piece that I don't have is this Payment Method object and the ID of it which needs to be passed to the Payment Intent.

novel raptor
#

No, there's no missing piece. You don't need that ID if you're collecting the payment information from the customer for the first time

#

Have you just tried completing the flow that you've built? Create the PI, complete the Payment Element fields with test data and click 'pay'?

winter yacht
#

Yes and it continues to give me the error that I am missing a Payment Method.

novel raptor
#

Can you share the pi_xxx?

winter yacht
novel raptor
#

I need the ID please

winter yacht
#

pi_3MhX2eHWEmh5fspz0wgyoie9

novel raptor
#

Ok, this is the actual error:

error: {
    code: "url_invalid",
    doc_url: "https://stripe.com/docs/error-codes/url-invalid",
    message: "Invalid URL: An explicit scheme (such as https) must be provided.",
    param: "return_url",
#

Your return_url neds to be absolute, not a relative path: return_url: "OrderSuccess.aspx",

winter yacht
#

it is different for development and production so I have to change it in ech environment. Is that correct?

novel raptor
#

Yes, maybe via an env variable or such

winter yacht
#

Hey, I got it to succeed. Yeah. Thank you. Now, I have one more question.

#

It didn't redirect correctly after my payment.

#

Do I need the redirect: 'if_required'

novel raptor
#

Are you only processing card payments?

winter yacht
#

yes

novel raptor
#
By default, stripe.confirmPayment will always redirect to your return_url after a successful confirmation. If you set redirect: "if_required", then stripe.confirmPayment will only redirect if your user chooses a redirect-based payment method.

Note: Setting if_required requires that you handle successful confirmations for redirect-based and non-redirect based payment methods separately. When a non-redirect based payment method is successfully confirmed, stripe.confirmPayment will resolve with a {paymentIntent} object.
#

Then omit it

winter yacht
#

I will omit it because it didn't redirect with the parameter.

#

Let me try again.

#

It works.

#

Thank you. You have been a tremendous help to me. Thank you so much. May God bless you.

novel raptor
#

np, glad you're on the right path!