public static void AddPinPayments(
            this IServiceCollection services,
            PinPaymentsOptions configureOptions
            )
        {
            configureOptions.CheckArgumentNull(nameof(configureOptions));

            services.TryAddSingleton(Options.Create(configureOptions));
            services.TryAddTransient <IPinService, PinService>();
        }
        public static void AddPinPayments(
            this IServiceCollection services,
            Action <PinPaymentsOptions> configuration)
        {
            configuration.CheckArgumentNull(nameof(configuration));

            var configureOptions = new PinPaymentsOptions();

            configuration(configureOptions);

            AddPinPayments(services, configureOptions);
        }
Exemple #3
0
        static void Main(string[] args)
        {
            // initialise PIN by setting your API Keys in appsettings.json
            // See:  https://pin.net.au/docs/api#keys
            var builder = new ConfigurationBuilder()
                          .SetBasePath(Directory.GetCurrentDirectory())
                          .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
                          .AddJsonFile("appsettings.development.json", optional: true, reloadOnChange: true);

            IConfigurationRoot configuration = builder.Build();

            var options = new PinPaymentsOptions();

            configuration.GetSection("PinPayments").Bind(options);

            System.Console.WriteLine($"BaseUrl: {options.BaseUrl}");
            System.Console.WriteLine($"ApiKey: {options.ApiKey}");

            PinService ps = new PinService(options);

            // https://pin.net.au/docs/api/test-cards
            // 5520000000000000 - Test Mastercard
            // 4200000000000000 - Test Visa

            var card = new Card();

            card.CardNumber  = "5520000000000000";
            card.CVC         = "111";
            card.ExpiryMonth = DateTime.Today.Month.ToString();              // Use the real Expiry
            card.ExpiryYear  = (DateTime.Today.Year + 1).ToString();         // Not my defaults!
            card.Name        = "Roland Robot";
            card.Address1    = "42 Sevenoaks St";
            card.Address2    = null;
            card.City        = "Lathlain";
            card.Postcode    = "6454";
            card.State       = "WA";
            card.Country     = "Australia";

            System.Console.WriteLine($"Charging API");
            var response = ps.Charge(new PostCharge {
                Amount = 1500, Card = card, Currency = "AUD", Description = "Desc", Email = "*****@*****.**", IPAddress = "127.0.0.1"
            });

            System.Console.WriteLine(response.Charge.Success);
            System.Console.WriteLine(response.Charge.Token);

            // Refunds - Pin supports partial refunds
            // https://pin.net.au/docs/api/customers#get-customers-charges

            System.Console.WriteLine($"Refunding");
            var refund = ps.Refund(response.Charge.Token, 200);

            refund = ps.Refund(response.Charge.Token, 100);

            System.Console.WriteLine($"Getting refunds for token {response.Charge.Token}");
            var refunds = ps.Refunds(response.Charge.Token);

            // Searching for a Charge
            // See https://pin.net.au/docs/api/charges#search-charges for more detail

            System.Console.WriteLine($"Searching for a charge");
            var respChargesSearch = ps.ChargesSearch(new Actions.ChargeSearch {
                Query = "", Sort = ChargeSearchSortEnum.Amount, SortDirection = SortDirectionEnum.Descending
            });

            System.Console.WriteLine(respChargesSearch.Count.ToString() + " transactions found");
            foreach (var r in respChargesSearch.Response)
            {
                System.Console.WriteLine(r.Description + " " + r.Amount.ToString());
            }

            var respChargeSearch = ps.Charge(respChargesSearch.Response[0].Token);

            System.Console.WriteLine(respChargeSearch.Response.Description);


            // Create Customer
            // See: https://pin.net.au/docs/api/customers#post-customers
            System.Console.WriteLine($"Creating customer");
            var customer = new Customer();

            customer.Email            = "*****@*****.**";
            customer.Card             = new Card();
            customer.Card.CardNumber  = "5520000000000000";
            customer.Card.ExpiryMonth = DateTime.Today.Month.ToString();              // Use the real Expiry
            customer.Card.ExpiryYear  = (DateTime.Today.Year + 1).ToString();         // Not my defaults!
            customer.Card.CVC         = "123";
            customer.Card.Name        = "Roland Robot";
            customer.Card.Address1    = "42 Sevenoaks St";
            customer.Card.Address2    = "";
            customer.Card.City        = "Lathlain";
            customer.Card.Postcode    = "6454";
            customer.Card.State       = "WA";
            customer.Card.Country     = "Australia";

            var respCustomer = ps.CustomerAdd(customer);

            System.Console.WriteLine("Customer token: " + respCustomer.Response.Token);

            // Get Customer
            System.Console.WriteLine($"Getting customer");
            var customers = ps.Customers();

            // Customers supports pagination
            System.Console.WriteLine($"Paginating customers");
            if (customers.Pagination.Pages > 1)
            {
                customers = ps.Customers(1);
            }

            // Update Customer
            System.Console.WriteLine($"Updating customer");
            customer = customers.Customer[0];

            customer.Card             = new Card();
            customer.Card.CardNumber  = "5520000000000000";
            customer.Card.ExpiryMonth = DateTime.Today.Month.ToString();
            customer.Card.ExpiryYear  = (DateTime.Today.Year + 2).ToString();
            customer.Card.CVC         = "123";
            customer.Card.Name        = "Roland Robot";
            customer.Card.Address1    = "42 Sevenoaks St";
            customer.Card.Address2    = "";
            customer.Card.City        = "Lathlain";
            customer.Card.Postcode    = "6454";
            customer.Card.State       = "WA";
            customer.Card.Country     = "Australia";

            customer.State = "NSW";
            var customerUpate = ps.CustomerUpate(customer);

            // Get a customer by token
            System.Console.WriteLine($"Getting customer by token");
            var current = ps.Customer(customerUpate.Customer.Token);

            var respCustomerCharge = ps.Charge(new PostCharge {
                IPAddress = "127.0.0.1", Amount = 1000, Description = "Charge by customer token: " + customer.Email, Email = customer.Email, CustomerToken = customer.Token
            });

            // Card Token
            // https://pin.net.au/docs/api/cards
            // 5520000000000000 - Test Mastercard
            // 4200000000000000 - Test Visa

            System.Console.WriteLine($"Creating card token");

            card             = new Card();
            card.CardNumber  = "5520000000000000";
            card.CVC         = "111";
            card.ExpiryMonth = DateTime.Today.Month.ToString();              // Use the real Expiry
            card.ExpiryYear  = (DateTime.Today.Year + 1).ToString();         // Not my defaults!
            card.Name        = "Roland Robot";
            card.Address1    = "42 Sevenoaks St";
            card.Address2    = "";
            card.City        = "Lathlain";
            card.Postcode    = "6454";
            card.State       = "WA";
            card.Country     = "Australia";

            var respCardCreate = ps.CardCreate(card);

            response = ps.Charge(new PostCharge {
                Amount = 1500, CardToken = respCardCreate.Response.Token, Currency = "AUD", Description = "Desc", Email = "*****@*****.**", IPAddress = "127.0.0.1"
            });
            System.Console.WriteLine(response.Charge.Success);

            // Card tokens can only be used once.
            // If you try and use it a second time, you will get the following message:
            response = ps.Charge(new PostCharge {
                Amount = 1500, CardToken = respCardCreate.Response.Token, Currency = "AUD", Description = "Desc", Email = "*****@*****.**", IPAddress = "127.0.0.1"
            });
            System.Console.WriteLine(response.Error);             // "token_already_used"
            System.Console.WriteLine(response.Description);       // "Token already used. Card tokens can only be used once, to create a charge or assign a card to a customer."
        }