1. Home
  2. Library
  3. SDK .NET
  4. Credit Card Charge – .NET

Credit Card Charge – .NET

THE POINT OF IMPLEMENTING SR PAGO IS TO BE ABLE TO CHARGE CREDIT CARDS. IN THIS MODULE WE WILL STUDY THE EASIEST WAY TO ACCOMPLISH THIS TASK.

Once you have the token as a result of the tokenization process you can do several processes, the must important one is charging the Credit Card that was tokenized.

Pre-requisites

To have end the tokenization process and have a valid token.

End the SDK installation and configuration

Process

1. Import the SrPago class

using SrPagoApi;
using SrPagoApi.Response;

2. Ensure Key and Secret are configured

SrPago.ApiKey = "APPLICATION KEY";
SrPago.ApiSecret = "APPLICATION SECRET";
SrPago.LiveMode = false;

3. Create a Dictionary object

Dictionary<string, object> chargeParams = new Dictionary<string, object>();
            chargeParams.Add("amount", <Monto de la compra>);
            chargeParams.Add("description", <Descripción de la operación>);
            chargeParams.Add("reference", <Agregar identificador interno>);
           chargeParams.Add("source", <Agregar el token>);
            chargeParams.Add("metadata", <Agregar metadata>);

Note: For more information about metadata please refer to Metadata chapter

4. Create a ChargeService object and request the operation:

ChargesService charges = new ChargesService();
            ChargesResponse charge = await charges.Create(chargeParams);
            if (charge.success)
            {
                //Exito
                Operation result = charge.result;
                ViewData["Message"] = result.authorization_code;
            }
            else
            {
                //Error
                string code = charge.error.code;
                string message = charge.error.message;
                ViewData["Message"] = "Hubo un error" + message;
            }

5. The service will answer with a json, to know more about this answer and the possible error codes please refer to the API documentation

NOTE: It is important to fill all the fields and send accurate metadata in order to prevent possible fraud threats.

Was this article helpful to you? Yes 7 No 1