locked
Automatic credit of user wallect account RRS feed

  • Question

  • User-527908287 posted
    Hello Forum,
    Please how can I create a user wallet in my website, as well as credit a user's wallet account automatically if using a payment gateway?
    Wednesday, May 27, 2020 3:10 PM

Answers

  • User379720387 posted

    I only know about PayPal and Stripe.

    PayPal is not developer friendly, you won't get any meaningful support, and their older APIs are poorly documented and littered with unfortunate choices. Once you are in the PayPal sandbox your session will get closed every few minutes, so you spend logging into PayPal tens of times per day, each day every day. It is a pain.

    Stripe is very developer friendly, you can get polite and knowledgeable support by chat. Fresh APIs very well documented and their dashboard allows you to see what is happening. All their API samples are dynamic, meaning they show the implementation with pre-popuated settings that are relevant for you. Stripe.net is a library that is a joy to work with.

    Here is how you create a customer in Stripe:

    StripeConfiguration.ApiKey = stAuthToken;
    
                var options = new CustomerCreateOptions
                {
                    Name = cName,
                    Description = cDescription,
                    Email = Email,
                    Phone = Mobile,
                    Metadata = new Dictionary<string, string>()
                    {
                        { "btId", btId.ToString() },
                        { "role", cDescription }
                    }
                };
                var service = new CustomerService();
                Customer customer = service.Create(options);
                customerId = customer.Id;
    
                if (customer.StripeResponse.StatusCode.ToString() == "OK") { isSuccess = true; }

    You can read more here.

    Did you see that section Response, that is what Stripe sends you back to your webhook. Stripe sends Events with the response from the previous link. A sample below.

    var reader = new StreamReader(Request.InputStream).ReadToEnd();
      {
        try
          {
          var stripeEvent = EventUtility.ConstructEvent(reader, Request.Headers["Stripe-Signature"], Secret);
    
    
                        if (stripeEvent.Type == Events.InvoiceSent)
                        {
                            //your logic goes here
                        }
                        else if (stripeEvent.Type == Events.CustomerCreated)
                        {
                            //your logic goes here
                        }

    There are many many Events which you will need to capture and act upon.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, May 28, 2020 1:20 AM

All replies

  • User409696431 posted

    Create a database table with columns for the user's ID and the amount in the wallet (initially zero).

    Follow the instructions for your payment gateway's API to know when a successful payment has been made, and add that amount to the user's existing amount in the database table.

    This is pretty basic logic.

    Wednesday, May 27, 2020 8:27 PM
  • User-527908287 posted
    Thank you Kathy,
    Am I to add the amount to the user's existing amount in the database manually after successful payment has been made? Or will it be done automatically? via API
    Wednesday, May 27, 2020 9:33 PM
  • User379720387 posted

    No, that is not how it works.

    The payment gateway sends you several JSON messages with payment status.

    It is up to you to parse that information and have logic in place to update your wallet.

    Wednesday, May 27, 2020 10:13 PM
  • User-527908287 posted
    Is there a way you could please show me examples ? I'm having difficultly on this. Thank you
    Wednesday, May 27, 2020 10:40 PM
  • User379720387 posted

    I only know about PayPal and Stripe.

    PayPal is not developer friendly, you won't get any meaningful support, and their older APIs are poorly documented and littered with unfortunate choices. Once you are in the PayPal sandbox your session will get closed every few minutes, so you spend logging into PayPal tens of times per day, each day every day. It is a pain.

    Stripe is very developer friendly, you can get polite and knowledgeable support by chat. Fresh APIs very well documented and their dashboard allows you to see what is happening. All their API samples are dynamic, meaning they show the implementation with pre-popuated settings that are relevant for you. Stripe.net is a library that is a joy to work with.

    Here is how you create a customer in Stripe:

    StripeConfiguration.ApiKey = stAuthToken;
    
                var options = new CustomerCreateOptions
                {
                    Name = cName,
                    Description = cDescription,
                    Email = Email,
                    Phone = Mobile,
                    Metadata = new Dictionary<string, string>()
                    {
                        { "btId", btId.ToString() },
                        { "role", cDescription }
                    }
                };
                var service = new CustomerService();
                Customer customer = service.Create(options);
                customerId = customer.Id;
    
                if (customer.StripeResponse.StatusCode.ToString() == "OK") { isSuccess = true; }

    You can read more here.

    Did you see that section Response, that is what Stripe sends you back to your webhook. Stripe sends Events with the response from the previous link. A sample below.

    var reader = new StreamReader(Request.InputStream).ReadToEnd();
      {
        try
          {
          var stripeEvent = EventUtility.ConstructEvent(reader, Request.Headers["Stripe-Signature"], Secret);
    
    
                        if (stripeEvent.Type == Events.InvoiceSent)
                        {
                            //your logic goes here
                        }
                        else if (stripeEvent.Type == Events.CustomerCreated)
                        {
                            //your logic goes here
                        }

    There are many many Events which you will need to capture and act upon.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, May 28, 2020 1:20 AM