#shaheer_api

1 messages ¡ Page 1 of 1 (latest)

steel bloomBOT
#

👋 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.

pallid ferry
#

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?

pallid surge
#

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

pallid ferry
#

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 the source field 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 ID req_xxx from 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 what CreateCreditCardSource does or what API calls it makes.

pallid surge
#

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;

}

pallid ferry
pallid surge
#

Thanks, let me try this.