コード例 #1
0
        public async Task Create_a_valid_charge_of_type_bank_slip()
        {
            // Arrange
            var chargeRequest = new ChargeRequestMessage
            {
                Method       = Constants.PaymentMethod.BANK_SLIP,
                CustomerId   = "31F26DC9D613403B837B678335B2CCB0",
                Email        = "*****@*****.**",
                InvoiceItems = new InvoiceItem[] { new InvoiceItem {
                                                       Description = "Mensalidade", PriceCents = 100000, Quantity = 1
                                                   } },
                PayerCustomer = PayerModelDataBuilder.CreateValid()
            };

            ChargeResponseMessage chargeTokenResponse;

            // Act
            using (var apiClient = new Charge())
            {
                chargeTokenResponse = await apiClient.CreateAsync(chargeRequest).ConfigureAwait(false);
            }

            // Assert
            Assert.That(chargeTokenResponse.Success, Is.True);
            Assert.That(chargeTokenResponse.Url, Is.Not.Empty);
        }
コード例 #2
0
        public async Task Create_a_new_invoice_with_custom_api_token_and_cancel_after()
        {
            // Arrange
            const string customApiToken = "74c265aedbfaea379bc0148fae9b5526";
            InvoiceModel invoice;
            InvoiceModel cancelInvoice;

            var customVariables = new List <CustomVariables>
            {
                new CustomVariables {
                    name = "TaxaIugu", value = "2,50"
                },
                new CustomVariables {
                    name = "TaxaPlataformaEdux", value = "1,00"
                }
            };

            var invoiceDate = DateTime.Now.AddDays(2);
            var newDate     = invoiceDate.AddDays(3).ToString("dd/MM/yyyy");

            var items = new List <InvoiceItem> {
                new InvoiceItem {
                    Description = "Mensalidade", PriceCents = 100000, Quantity = 1
                }
            };

            var customer = new CustomerRequestMessage
            {
                Email           = "*****@*****.**",
                Name            = "Client Name",
                CustomVariables = customVariables
            };

            // Act
            using (var apiInvoice = new Invoice())
                using (var apiCustomer = new Customer())
                    using (var apiSubscription = new Subscription())
                        using (var apiPlan = new Plans())
                        {
                            var customerResponse = await apiCustomer.CreateAsync(customer, null).ConfigureAwait(false);

                            var radomPlan = Guid.NewGuid().ToString();
                            var plan      = await apiPlan.CreateAsync($"{radomPlan}-12x", $"{radomPlan}-Plan", 1, "months", 0, "BRL", null, null, Constants.PaymentMethod.BANK_SLIP).ConfigureAwait(false);

                            var subscriptionItems = new List <SubscriptionSubitem> {
                                new SubscriptionSubitem {
                                    description = "Mensalidade", price_cents = 65000, quantity = 1, recurrent = true
                                }
                            };
                            var subscription = await apiSubscription.CreateAsync(new SubscriptionRequestMessage(customerResponse.id)
                            {
                                PlanId          = plan.identifier,
                                IsCreditBased   = false,
                                CustomVariables = customVariables,
                                Subitems        = subscriptionItems
                            }, customApiToken).ConfigureAwait(false);

                            var invoiceItems = new[] { new Item {
                                                           description = "Mensalidade", price_cents = 65000, quantity = 1
                                                       } };
                            var request = new InvoiceRequestMessage("*****@*****.**", invoiceDate, invoiceItems)
                            {
                                SubscriptionId             = subscription.id,
                                CustomVariables            = customVariables.ToArray(),
                                Payer                      = PayerModelDataBuilder.CreateValid(),
                                EnableLateFine             = true,
                                LatePaymentFine            = "2%",
                                EnableProportionalDailyTax = true,
                                PaymentMethod              = Constants.PaymentMethod.BANK_SLIP
                            };

                            var current = await apiInvoice.CreateAsync(request, customApiToken).ConfigureAwait(false);

                            invoice = await apiInvoice.DuplicateAsync(current.id, new InvoiceDuplicateRequestMessage(newDate), customApiToken).ConfigureAwait(false);

                            cancelInvoice = await apiInvoice.GetAsync(current.id, customApiToken).ConfigureAwait(false);
                        };

            // Assert
            Assert.That(invoice, Is.Not.Null);
            Assert.That(invoice.status, Is.EqualTo(Constants.InvoiceStatus.PENDING));
            Assert.That(cancelInvoice.status, Is.EqualTo(Constants.InvoiceStatus.CANCELED));
        }