admin管理员组

文章数量:1134246

I am currently working on the proof of concept project where I need to use Stripe's Connect direct charge function to charge a connected account when a payment is made. I do not have much experience with payment gateways, but I managed to set up a connection between my Stripe account and application and successfully received payments. However, I am struggling to implement the direct charge function.

I have followed this documentation, where I am using the Stripe-hosted page to charge the customer. However, when I click the button which should be taking me to the hosted page, nothing happens, and I get a blank screen on my solution.

This is the one direct charge which is not working and giving me a blank screen.

var options = new Stripe.Checkout.SessionCreateOptions
{
    LineItems = new List<Stripe.Checkout.SessionLineItemOptions>
    {
    new Stripe.Checkout.SessionLineItemOptions
        {
                PriceData = new Stripe.Checkout.SessionLineItemPriceDataOptions
                    {
                    Currency = "gbp",
                    ProductData = new Stripe.Checkout.SessionLineItemPriceDataProductDataOptions
                    {
                        Name = "T-shirt",
                    },
                    UnitAmount = 1000,
                },
                Quantity = 1,
            },
    },
    PaymentIntentData = new Stripe.Checkout.SessionPaymentIntentDataOptions
    {
        ApplicationFeeAmount = 123,
    },
    Mode = "payment",
    SuccessUrl = "={CHECKOUT_SESSION_ID}",
};
var requestOptions = new RequestOptions
{
    StripeAccount = "ACCOUNTID",
};

var service = new Stripe.Checkout.SessionService();
service.Create(options, requestOptions);

return new StatusCodeResult(303);

This code that I have works perfectly with no issues. Takes me to the Stripe-hosted payment page

public IActionResult CheckOut(ProductViewModel product)
{
    var domain = "http://localhost:5184/";

    var options = new Stripe.Checkout.SessionCreateOptions
    {
        SuccessUrl = domain + $"CheckOut/Confirm",
        CancelUrl = domain + $"CheckOut/Cancel",
        LineItems = new List<Stripe.Checkout.SessionLineItemOptions>
        {
        new Stripe.Checkout.SessionLineItemOptions
            {
                    PriceData = new Stripe.Checkout.SessionLineItemPriceDataOptions
                        {
                        Currency = "gbp",
                        ProductData = new Stripe.Checkout.SessionLineItemPriceDataProductDataOptions
                        {
                            Name = "T-shirt",
                        },
                        UnitAmount = 1000,
                    },
                    Quantity = 1,
                },
        },
        Mode = "payment"

    };

    var service = new Stripe.Checkout.SessionService();
    Stripe.Checkout.Session session = service.Create(options);

    Response.Headers.Add("Location", session.Url);
    return new StatusCodeResult(303);
}

I am currently working on the proof of concept project where I need to use Stripe's Connect direct charge function to charge a connected account when a payment is made. I do not have much experience with payment gateways, but I managed to set up a connection between my Stripe account and application and successfully received payments. However, I am struggling to implement the direct charge function.

I have followed this documentation, where I am using the Stripe-hosted page to charge the customer. However, when I click the button which should be taking me to the hosted page, nothing happens, and I get a blank screen on my solution.

This is the one direct charge which is not working and giving me a blank screen.

var options = new Stripe.Checkout.SessionCreateOptions
{
    LineItems = new List<Stripe.Checkout.SessionLineItemOptions>
    {
    new Stripe.Checkout.SessionLineItemOptions
        {
                PriceData = new Stripe.Checkout.SessionLineItemPriceDataOptions
                    {
                    Currency = "gbp",
                    ProductData = new Stripe.Checkout.SessionLineItemPriceDataProductDataOptions
                    {
                        Name = "T-shirt",
                    },
                    UnitAmount = 1000,
                },
                Quantity = 1,
            },
    },
    PaymentIntentData = new Stripe.Checkout.SessionPaymentIntentDataOptions
    {
        ApplicationFeeAmount = 123,
    },
    Mode = "payment",
    SuccessUrl = "https://example.com/success?session_id={CHECKOUT_SESSION_ID}",
};
var requestOptions = new RequestOptions
{
    StripeAccount = "ACCOUNTID",
};

var service = new Stripe.Checkout.SessionService();
service.Create(options, requestOptions);

return new StatusCodeResult(303);

This code that I have works perfectly with no issues. Takes me to the Stripe-hosted payment page

public IActionResult CheckOut(ProductViewModel product)
{
    var domain = "http://localhost:5184/";

    var options = new Stripe.Checkout.SessionCreateOptions
    {
        SuccessUrl = domain + $"CheckOut/Confirm",
        CancelUrl = domain + $"CheckOut/Cancel",
        LineItems = new List<Stripe.Checkout.SessionLineItemOptions>
        {
        new Stripe.Checkout.SessionLineItemOptions
            {
                    PriceData = new Stripe.Checkout.SessionLineItemPriceDataOptions
                        {
                        Currency = "gbp",
                        ProductData = new Stripe.Checkout.SessionLineItemPriceDataProductDataOptions
                        {
                            Name = "T-shirt",
                        },
                        UnitAmount = 1000,
                    },
                    Quantity = 1,
                },
        },
        Mode = "payment"

    };

    var service = new Stripe.Checkout.SessionService();
    Stripe.Checkout.Session session = service.Create(options);

    Response.Headers.Add("Location", session.Url);
    return new StatusCodeResult(303);
}
Share Improve this question edited Jan 8 at 4:51 marc_s 754k183 gold badges1.4k silver badges1.5k bronze badges asked Jan 7 at 21:46 Abdullah ErgunAbdullah Ergun 112 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

I found the solution. I needed to add at the end of the code.

Response.Headers.Add("Location", session.Url);

本文标签: cStripe Connect Direct Charges in ASPNET MVCStack Overflow