المفروض الـ Stripe يرجعلي ان الراجل دفع عادي بس دا مش بيحصل لأن مفيش حاجة عندي في الـ Endpoint بتاخد الحوار دا فهو هتلاقي الـ Order اتدفع في الـ Stripe بس مدفعش عندي في البروجكت

هنعمل Endpoint اسمها Webhook عشان الـ Stripe يكلمها يقولي دفع ولا لا فأنا مش هثق في الـ Angular بس هثق في الـ Payment Gateway

هنروح في الـ Stripe نضيف الـ API Url بتاعنا ونختار الـ Event بتاع Payment Intent واختار Failed او Succeeded

// Payments
 
[HttpPost("webhook")] // POST : /api/Payments/webhook
public async Task<IActionResult> StripeWebhook()
{
 
}

To use Stripe webhooks on your local host, you’ll need to set up a way for Stripe to communicate with your local server. Since your local server isn’t accessible from the internet, you’ll need to use a tool like ngrok to create a secure tunnel to your local server. Here’s a step-by-step guide to help you set this up:

  1. Install ngrok:

    • Download and install ngrok from ngrok’s website.
    • Once installed, you can run it from the command line.
  2. Run ngrok:

    • Open a terminal and run the following command to start ngrok on the port your local server is running (e.g., port 5000):

      1ngrok http 5000

    • This will provide you with a public URL that forwards requests to your local server. You’ll see something like http://abcd1234.ngrok.io.

  3. Set up your Stripe webhook:

    • Log in to your Stripe Dashboard.
    • Go to Developers > Webhooks.
    • Click on “Add endpoint” and enter the ngrok URL you received, appending the specific path your webhook endpoint listens to (e.g., http://abcd1234.ngrok.io/webhook).
    • Select the events you want to listen to, or select “Receive all events” for testing purposes.
  4. Implement the webhook endpoint in your .NET application:

    • Make sure your .NET application has an endpoint to handle the webhook events. Here’s a basic example using ASP.NET Core:

      C#

      Collapse

      1[ApiController] 2[Route("webhook")] 3public class WebhookController : ControllerBase 4{ 5 [HttpPost] 6 public async Task<IActionResult> Handle() 7 { 8 var json = await new StreamReader(HttpContext.Request.Body).ReadToEndAsync(); 9 10 try 11 { 12 var stripeEvent = EventUtility.ConstructEvent( 13 json, 14 Request.Headers["Stripe-Signature"], 15 "your_stripe_webhook_secret" 16 ); 17 18 // Handle the event 19 if (stripeEvent.Type == Events.PaymentIntentSucceeded) 20 { 21 var paymentIntent = stripeEvent.Data.Object as PaymentIntent; 22 // Handle successful payment intent 23 } 24 else 25 { 26 // Handle other event types 27 } 28 29 return Ok(); 30 } 31 catch (StripeException e) 32 { 33 return BadRequest(); 34 } 35 } 36}

    • Replace "your_stripe_webhook_secret" with your actual webhook secret from the Stripe Dashboard.

  5. Test your webhook:

    • You can test your webhook by triggering events in the Stripe Dashboard or using the Stripe CLI to send test events to your endpoint.

By following these steps, you should be able to receive and handle Stripe webhooks on your local development environment.

الصح

نشتغل على Local Environment

Title Unavailable | Site Unreachable Install by scoop Scoop

1. Open PowerShell
2. Install Scoop Package Manager
	--> iwr -useb get.scoop.sh | iex 
3. May be need to run this command [if asked]
	--> Set-ExecutionPolicy RemoteSigned -Scope CurrentUser
4. in case Step.3 Executed, Repeat the Executing of Step.2
5. Add Stripe
	-->  scoop bucket add stripe https://github.com/stripe/scoop-stripe-cli.git
6. Install Stripe
	-->  scoop install stripe
7. Login to Your Stripe Account [Will Open Window at Your Browser To Verify Login]
	--> stripe login
8. Listen to Stripe in order to track payment_intent events
	--> stripe listen -f https://localhost:7054/api/Payments/webhook -e payment_intent.succeeded,payment_intent.payment_failed