#shaheer_api
1 messages ¡ Page 1 of 1 (latest)
đ Welcome to your new thread!
â˛ď¸ We'll be here soon! Typically we respond in a few minutes, but sometimes we might take a bit longer if the server is busy or if you have a particularly tricky question.
âąď¸ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can always start a new thread if you have another question.
đ This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1273946079963906068
đ Have more to share? Add more details, code, screenshots, videos, etc. below.
hi! hmm can you share more of the code and exact request ID req_xxx from errors? and a link to the guides you're using in building this?
My code is:
customer = StripeHelper.GetStripeHelper(StripeAccountType.ConnectAccount).CreateCustomer(
checkoutObject.PayingAccount.Name,
checkoutObject.PayingAccount.Email,
checkoutObject.PayingAccount.Phone,
checkoutObject.PayingAccount.AccountTypeId.ToString().SplitByUpperCase(),
null,
null,
providerConnectedAccount.Id,
msgs);
var stripeHelper = StripeHelper.GetStripeHelper(StripeAccountType.ConnectAccount);
var source = stripeHelper.CreateCreditCardSource(stripeToken, providerConnectedAccount.Id, msgs);
stripeHelper.AddNewCardToCustomer(customer.Id, source, null, msgs);
for client side:
$('#btn-paywithnewcard').click(function () {
$('#btn-paywithnewcard').html('Processing...');
disableButtons();
stripe.createToken(card).then(function (result) {
if (result.error) {
// Inform the customer that there was an error.
var errorElement = document.getElementById('card-errors');
errorElement.textContent = result.error.message;
// $('#btn-paywithnewcard').html('Review Purchase');
enableButtons();
} else {
// Send the token to your server.
stripeTokenHandler(result.token);
}
});
});
Current error: Invalid token id: tok_xxxx
If i remove providerConnectedAccount.Id from CreateCreditCardSource, it will create the souce without error but it will not recognize the customer
hmm doesn't help much since I don't have the implementation of all these CreateCreditCardSource functions and what actual API/SDK calls that make. Can you break it down?
stripe.createToken
is there a reason you're legacy APIs like Tokens and thesourcefield on Customers, instead of the PaymentMethods API that replaced them a few years ago?
Current error: Invalid token id: tok_xxxx
what is the request IDreq_xxxfrom the error?
f i remove providerConnectedAccount.Id from CreateCreditCardSource, it will create the souce without error but it will not recognize the customer
can't say much since I don't know whatCreateCreditCardSourcedoes or what API calls it makes.
Request Id: req_15j5zmtV7WsxeS
i can share the methods with you
public Stripe.Source CreateCreditCardSource(string token, string stripeAccountId, SystemMessages msgs)
{
if (msgs.IsEmpty()) msgs = new SystemMessages();
var options = new Stripe.SourceCreateOptions()
{
Type = "card",
Token = token,
};
var requestOptions = new Stripe.RequestOptions();
if (stripeAccountId.IsNotEmpty())
requestOptions.StripeAccount = stripeAccountId;
Stripe.Source source = null;
try
{
source = GetSourceService().Create(options, requestOptions);
if ((source?.Card?.Country.IsEmpty() ?? true) || source?.Card?.Country != "US")
throw new StripeException("Card origin not allowed");
}
catch (StripeException ex)
{
msgs.Add(ex.Message, MessageType.UserError, ex);
msgs.Add($"Payment source was not created", MessageType.UserError);
}
return source;
}
public Stripe.Card AddNewCardToCustomer(string customerId, Stripe.Source source, string stripeAccountId, SystemMessages msgs)
{
var options = new Stripe.CardCreateOptions()
{
Source = source.Id
};
var requestOptions = new Stripe.RequestOptions();
if (stripeAccountId.IsNotEmpty())
requestOptions.StripeAccount = stripeAccountId;
Stripe.Card card = null;
try
{
card = GetCardService().Create(customerId, options, requestOptions);
}
catch (StripeException ex)
{
msgs.Add(ex.Message, MessageType.UserError);
}
return card;
}
that error is expected really, you can't create the Token on one account and use it on another.
What you should do is create the Token on the connected account, by passing the StripeAccount ID on the frontend when you initialise stripe.js https://docs.stripe.com/connect/authentication#adding-the-connected-account-id-to-a-client-side-application
Thanks, let me try this.