#mnord
1 messages ยท Page 1 of 1 (latest)
Hi! Let me help you with this.
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() } }
};
The PaymentIntent is not directly an alternative for Card Element.
Have you changed your frontend component or your backend integration?
Yes
Have you changed your frontend component or your backend integration? ๐
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?
You need to create the payment method information on the frontend with Stripe.js.
Please follow this guide to see the whole flow: https://stripe.com/docs/payments/accept-a-payment?platform=web&ui=elements
I am using WebForms not MVC. So, do I just need to add AutomaticPaymentMethods to make it work?
How are you collecting payment information from your customers? That's the missing component here
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?
Ok, that creates a Payment Intent. The next step is to collect payment information from your customer in your app/site, and confirm the payment: https://stripe.com/docs/payments/accept-a-payment?platform=web&ui=elements#web-submit-payment
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',
});
});
Ok, and is the Payment Element mounted in your frontend application?
See above code
I see the code. Is it working is the question?
Have you tried completing the form with test data and completing the payment?
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.
When do you get that error?
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.
What is your understanding of the automatic payment methods parameter?
very little
It doesn't work like you expect it to it seems
I had specified payment method of card but it still said I didn't have a payment method specified.
It's for calculating which payment method types (i.e. card, bank debits, etc) will be shown to your customers in the Payment Element
I recommend following this guide: https://stripe.com/docs/payments/quickstart?client=html&lang=dotnet
I am using WebForms not MVC.
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.
I don't know enough about .NET to know what that means I'm afriad
I only need to know how to correctly specifiy the payment method in the PaymentIntent.
That's the data you need to collect from your customers in the Payment Element
But, we don't have access to the text boxes that Stripe generates in the payment element.
Then how are you expecting to collect payment information from your users in a PCI compliant manner?
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?
Sure, you'd pass the payment_method parameter when you create the Payment Intent: https://stripe.com/docs/api/payment_intents/create#create_payment_intent-payment_method
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
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
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?
I don't know how to collect that from the Stripe text boxes that are generated in the Payment Element
TheconfirmPaymentmethod 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 triggerconfirmPayment, 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.
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.
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'?
Yes and it continues to give me the error that I am missing a Payment Method.
Can you share the pi_xxx?
I need the ID please
pi_3MhX2eHWEmh5fspz0wgyoie9
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",
it is different for development and production so I have to change it in ech environment. Is that correct?
Yes, maybe via an env variable or such
Hey, I got it to succeed. Yeah. Thank you. Now, I have one more question.
It didn't redirect correctly after my payment.
D stripe.confirmPayment({
elements,
confirmParams: {
return_url: 'https://localhost/GreenThumbHub.Web/OrderSuccess.aspx',
},
redirect: 'if_required',
});
Do I need the redirect: 'if_required'
Are you only processing card payments?
yes
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
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.
np, glad you're on the right path!