public async Task MapsPagingProperties()
        {
            // given
            var subject = new PaymentsClient(_clientConfiguration);

            var firstPageRequest = new GetPaymentsRequest
            {
                Limit = 1
            };

            // when
            var firstPageResult = await subject.GetPageAsync(firstPageRequest);

            var secondPageRequest = new GetPaymentsRequest
            {
                After = firstPageResult.Meta.Cursors.After,
                Limit = 2
            };

            var secondPageResult = await subject.GetPageAsync(secondPageRequest);

            // then
            Assert.That(firstPageResult.Items.Count(), Is.EqualTo(firstPageRequest.Limit));
            Assert.That(firstPageResult.Meta.Limit, Is.EqualTo(firstPageRequest.Limit));
            Assert.That(firstPageResult.Meta.Cursors.Before, Is.Null);
            Assert.That(firstPageResult.Meta.Cursors.After, Is.Not.Null);

            Assert.That(secondPageResult.Items.Count(), Is.EqualTo(secondPageRequest.Limit));
            Assert.That(secondPageResult.Meta.Limit, Is.EqualTo(secondPageRequest.Limit));
            Assert.That(secondPageResult.Meta.Cursors.Before, Is.Not.Null);
            Assert.That(secondPageResult.Meta.Cursors.After, Is.Not.Null);
        }
        public void CanProcessLotOfData()
        {
            var clientConfiguration = GetDefaultDataClientConfiguration();
            var dataClient          = new JustGivingDataClient(clientConfiguration);

            CreatePaymentsClient(dataClient);

            var startDate = TestContext.StartDate;
            var endDate   = startDate.AddMonths(3);

            var data = new List <PaymentSummary>();

            while (data.Count == 0 && startDate <= TestContext.StartDate.AddMonths(9))
            {
                var response = PaymentsClient.RetrievePaymentsBetween(startDate, endDate);
                if (response.Any())
                {
                    data.AddRange(response);
                }
                startDate = endDate.AddDays(1);
                endDate   = startDate.AddMonths(3);
            }

            Assert.That(data.Count > 0);
        }
        public async Task UpdatesPaymentReplacingMetadata()
        {
            // given
            var payment = await _resourceFactory.CreatePaymentFor(_mandate);

            var request = new UpdatePaymentRequest
            {
                Id       = payment.Id,
                Metadata = new Dictionary <string, string>
                {
                    ["Key4"] = "Value4",
                    ["Key5"] = "Value5",
                    ["Key6"] = "Value6",
                },
            };

            var subject = new PaymentsClient(_clientConfiguration);

            // when
            var result = await subject.UpdateAsync(request);

            var actual = result.Item;

            // then
            Assert.That(actual, Is.Not.Null);
            Assert.That(actual.Id, Is.EqualTo(payment.Id));
            Assert.That(actual.Metadata, Is.EqualTo(request.Metadata));
        }
        public async Task ReturnsIndividualPayment()
        {
            // given
            var subject = new PaymentsClient(_clientConfiguration);
            var payment = await _resourceFactory.CreatePaymentFor(_mandate);

            // when
            var result = await subject.ForIdAsync(payment.Id);

            var actual = result.Item;

            // then
            Assert.That(actual, Is.Not.Null);
            Assert.That(actual.Id, Is.Not.Null);
            Assert.That(actual.Amount, Is.EqualTo(payment.Amount));
            Assert.That(actual.AmountRefunded, Is.EqualTo(0));
            Assert.That(actual.ChargeDate, Is.EqualTo(payment.ChargeDate));
            Assert.That(actual.Currency, Is.EqualTo(payment.Currency));
            Assert.That(actual.CreatedAt, Is.Not.Null.And.Not.EqualTo(default(DateTimeOffset)));
            Assert.That(actual.Description, Is.EqualTo(payment.Description));
            Assert.That(actual.Links.Creditor, Is.EqualTo(payment.Links.Creditor));
            Assert.That(actual.Links.Mandate, Is.EqualTo(payment.Links.Mandate));
            Assert.That(actual.Metadata, Is.EqualTo(payment.Metadata));
            Assert.That(actual.Reference, Is.EqualTo(payment.Reference));
            Assert.That(actual.Status, Is.EqualTo(payment.Status));
        }
        private void InitWalletStripe()
        {
            try
            {
                var stripePublishableKey = ListUtils.SettingsSiteList?.StripeId ?? "";
                if (!string.IsNullOrEmpty(stripePublishableKey))
                {
                    PaymentConfiguration.Init(stripePublishableKey);
                    Stripe = new Stripe(this, stripePublishableKey);

                    MPaymentsClient = WalletClass.GetPaymentsClient(this, new WalletClass.WalletOptions.Builder()
                                                                    .SetEnvironment(WalletConstants.EnvironmentTest)
                                                                    .SetTheme(WalletConstants.ThemeLight)
                                                                    .Build());

                    IsReadyToPay();
                }
                else
                {
                    Toast.MakeText(this, GetText(Resource.String.Lbl_ErrorConnectionSystemStripe), ToastLength.Long).Show();
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
Example #6
0
        public async Task SubmitPayment()
        {
            var paymentRequest = PaymentsControllerTests.GetPaymentRequest();
            var acquirer       = new Mock <IAcquirer>();

            BankRegistryMock.SetAcquirer(MerchantId, acquirer.Object);

            var acquirerResponse = new AcquirerResponse
            {
                AcquirerPaymentId = "0123-454543-bb",
                MerchantId        = MerchantId,
                Status            = PaymentStatus.Refused
            };

            acquirer.Setup(t => t.SubmitPayment(It.IsAny <PaymentRequest>()))
            .Returns(Task.FromResult(acquirerResponse));

            // Get JWT
            var jwt = await MerchantClient.AuthenticateAsync(new AuthenticationRequest
            {
                Login    = Merchant.Login,
                Password = Merchant.Password,
            });

            PaymentClient = new PaymentsClient(HttpClient.BaseAddress.ToString(), HttpClient, () => jwt.JwtToken);
            var paymentResponse = await PaymentClient.PostPaymentAsync(paymentRequest);

            Assert.AreEqual(acquirerResponse.AcquirerPaymentId, paymentResponse.Id);
            Assert.AreEqual(acquirerResponse.Status, paymentResponse.Status);
            Assert.AreEqual(paymentRequest.Amount, paymentResponse.Amount);
            Assert.AreEqual(paymentRequest.Currency, paymentResponse.Currency);
            Assert.AreEqual(paymentRequest.ExpiryMonth, paymentResponse.ExpiryMonth);
            Assert.AreEqual(paymentRequest.ExpiryYear, paymentResponse.ExpiryYear);
            Assert.AreEqual("XXXXXX7890", paymentResponse.MaskedCardNumber);
        }
Example #7
0
 public LoansService(LoansRepository loansRepository, ILogger <LoansService> logger, Mapper mapper, PaymentsClient paymentsClient, TransactionsClient transactionsClient)
 {
     this.loansRepository    = loansRepository;
     this.logger             = logger;
     this.mapper             = mapper;
     this.paymentsClient     = paymentsClient;
     this.transactionsClient = transactionsClient;
 }
        public async Task CreatesAndCancelsConflictingPayment()
        {
            // given
            var createRequest = new CreatePaymentRequest
            {
                Amount      = 500,
                ChargeDate  = DateTime.Now.AddMonths(1),
                Description = "Sandbox Payment",
                Currency    = "GBP",
                Links       = new CreatePaymentLinks {
                    Mandate = _mandate.Id
                },
                Metadata = new Dictionary <string, string>
                {
                    ["Key1"] = "Value1",
                    ["Key2"] = "Value2",
                    ["Key3"] = "Value3",
                },
                Reference = "REF123456"
            };

            var subject = new PaymentsClient(_clientConfiguration);

            // when
            await subject.CreateAsync(createRequest);

            var creationResult = await subject.CreateAsync(createRequest);

            var cancelRequest = new CancelPaymentRequest
            {
                Id       = creationResult.Item.Id,
                Metadata = new Dictionary <string, string>
                {
                    ["Key4"] = "Value4",
                    ["Key5"] = "Value5",
                    ["Key6"] = "Value6",
                },
            };

            var cancellationResult = await subject.CancelAsync(cancelRequest);

            // then
            Assert.That(creationResult.Item.Id, Is.Not.Null);
            Assert.That(creationResult.Item.Amount, Is.EqualTo(createRequest.Amount));
            Assert.That(creationResult.Item.AmountRefunded, Is.Not.Null);
            Assert.That(creationResult.Item.ChargeDate, Is.Not.Null.And.Not.EqualTo(default(DateTime)));
            Assert.That(creationResult.Item.CreatedAt, Is.Not.Null.And.Not.EqualTo(default(DateTimeOffset)));
            Assert.That(creationResult.Item.Currency, Is.EqualTo(createRequest.Currency));
            Assert.That(creationResult.Item.Description, Is.EqualTo(createRequest.Description));
            Assert.That(creationResult.Item.Links.Creditor, Is.EqualTo(_creditor.Id));
            Assert.That(creationResult.Item.Links.Mandate, Is.EqualTo(_mandate.Id));
            Assert.That(creationResult.Item.Metadata, Is.EqualTo(createRequest.Metadata));
            Assert.That(creationResult.Item.Reference, Is.EqualTo(createRequest.Reference));
            Assert.That(creationResult.Item.Status, Is.Not.Null.And.Not.EqualTo(PaymentStatus.Cancelled));

            Assert.That(cancellationResult.Item.Status, Is.EqualTo(PaymentStatus.Cancelled));
        }
Example #9
0
        private Payment GetPayment(DataClientConfiguration clientConfiguration, int paymentId = 0)
        {
            var client = new JustGivingDataClient(clientConfiguration);

            CreatePaymentsClient(client);
            var payment = PaymentsClient.RetrieveReport <Payment>(paymentId == 0 ? TestContext.KnownGiftAidPaymentId : paymentId);

            return(payment);
        }
        public void ResourceExists_ReturnsPayment_RawJson()
        {
            var clientConfiguration = GetDefaultDataClientConfiguration()
                                      .With((clientConfig) => clientConfig.WireDataFormat = WireDataFormat.Json);
            var client = new JustGivingDataClient(clientConfiguration);

            CreatePaymentsClient(client);
            var payment = PaymentsClient.RetrieveReport <Payment>(TestContext.KnownDonationPaymentId);

            Assert.IsNotNull(payment);
        }
 public DataFetcher(TransactionsClient transactionsClient,
                    AccountsClient accountsClient,
                    PaymentsClient paymentsClient,
                    CardsClient cardsClient,
                    LoansClient loansClient)
 {
     this.transactionsClient = transactionsClient;
     this.accountsClient     = accountsClient;
     this.paymentsClient     = paymentsClient;
     this.cardsClient        = cardsClient;
     this.loansClient        = loansClient;
 }
        public void ResourceDoesNotExist_ThrowsNotFoundException()
        {
            var clientConfiguration = GetDefaultDataClientConfiguration()
                                      .With((clientConfig) => clientConfig.WireDataFormat         = WireDataFormat.Json)
                                      .With((clientConfig) => clientConfig.IsZipSupportedByClient = true);

            var client = new JustGivingDataClient(clientConfiguration);

            CreatePaymentsClient(client);

            Assert.Throws <ResourceNotFoundException>(() => PaymentsClient.RetrieveReport <Payment>(BadPaymentId));
        }
    private void Start()
    {
        Instance = this;

        DontDestroyOnLoad(this);
        DontDestroyOnLoad(gameObject);

        // Load Payments.
        PaymentsClient.Load(TemplateLoaded,
                            () =>
                            { Debug.LogError("[SHOP] Template is not retrieved."); });
    }
 public BatchesBranchService(ILogger <BatchesBranchService> logger,
                             AccountsClient accountsClient,
                             LoansClient loansClient,
                             PaymentsClient paymentsClient,
                             UsersClient usersClient)
 {
     this.logger         = logger;
     this.accountsClient = accountsClient;
     this.loansClient    = loansClient;
     this.paymentsClient = paymentsClient;
     this.usersClient    = usersClient;
 }
        public async Task CallsGetPaymentsEndpoint()
        {
            // given
            var subject = new PaymentsClient(_clientConfiguration);

            // when
            await subject.GetPageAsync();

            // then
            _httpTest
            .ShouldHaveCalled("https://api.gocardless.com/payments")
            .WithVerb(HttpMethod.Get);
        }
        public void DateRange_CannotExceedThreeMonths()
        {
            var clientConfiguration = GetDefaultDataClientConfiguration();
            var startDate           = DateTime.Now.Date.AddYears(-2);
            var endDate             = startDate.AddYears(1);
            var client = new JustGivingDataClient(clientConfiguration);

            CreatePaymentsClient(client);

            var exception = Assert.Throws <ErrorResponseException>(() => PaymentsClient.RetrievePaymentsBetween(startDate, endDate));

            Assert.That(exception.Message.Contains("400"));
        }
        public async Task CallsIndividualPaymentsEndpoint()
        {
            // given
            var subject = new PaymentsClient(_clientConfiguration);
            var id      = "PM12345678";

            // when
            await subject.ForIdAsync(id);

            // then
            _httpTest
            .ShouldHaveCalled("https://api.gocardless.com/payments/PM12345678")
            .WithVerb(HttpMethod.Get);
        }
        public void When_GettingPaymentReportForKnownPaymentId_DataIsReturned(PaymentType paymentType, DataFileFormat fileFormat)
        {
            var clientConfiguration = GetDefaultDataClientConfiguration()
                                      .With((clientConfig) => clientConfig.WireDataFormat = WireDataFormat.Other);

            var client = new JustGivingDataClient(clientConfiguration);

            CreatePaymentsClient(client);

            var payment = PaymentsClient.RetrieveReport(GetPaymentId(paymentType), fileFormat);

            AssertResponseDoesNotHaveAnError(payment);
            Assert.IsNotNull(payment);
        }
        public void IdIsNullOrWhiteSpaceThrows(string id)
        {
            // given
            var subject = new PaymentsClient(_clientConfiguration);

            // when
            AsyncTestDelegate test = () => subject.ForIdAsync(id);

            // then
            var ex = Assert.ThrowsAsync <ArgumentException>(test);

            Assert.That(ex.Message, Is.Not.Null);
            Assert.That(ex.ParamName, Is.EqualTo(nameof(id)));
        }
 public PanelsBranchService(ILogger <PanelsBranchService> logger,
                            TransactionsClient transactionsClient,
                            PaymentsClient paymentsClient,
                            LoansClient loansClient,
                            AccountsClient accountsClient,
                            CardsClient cardsClient
                            )
 {
     this.logger             = logger;
     this.transactionsClient = transactionsClient;
     this.paymentsClient     = paymentsClient;
     this.loansClient        = loansClient;
     this.accountsClient     = accountsClient;
     this.cardsClient        = cardsClient;
 }
        public void CreatePaymentRequestIsNullThrows()
        {
            // given
            var subject = new PaymentsClient(_clientConfiguration);

            CreatePaymentRequest request = null;

            // when
            AsyncTestDelegate test = () => subject.CreateAsync(request);

            // then
            var ex = Assert.ThrowsAsync <ArgumentNullException>(test);

            Assert.That(ex.ParamName, Is.EqualTo(nameof(request)));
        }
Example #22
0
        /// <summary>
        /// Creates a new instance of the QuickPayClient
        /// </summary>
        /// <param name="baseUrl">URL for API, if null it defaults to QuickPays standard URL</param>
        /// <param name="baseUrlInvoicing">URL for Invoicing API, if null it defaults to QuickPays standard URL</param>
        /// <param name="apiKey"></param>
        /// <param name="privateKey"></param>
        /// <param name="userKey"></param>
        public QuickPayClient(string baseUrl, string baseUrlInvoicing, string apiKey, string privateKey, string userKey)
        {
            _url          = baseUrl ?? "https://api.quickpay.net/";
            _urlInvoicing = baseUrlInvoicing ?? "https://invoicing.quickpay.net/";
            _apiKey       = apiKey;
            _privateKey   = privateKey;
            _userKey      = userKey;
            _httpClient   = BuildHttpClient(_url, _apiKey, null);

            Callbacks     = new CallbacksClient(_privateKey);
            Cards         = new CardsClient(_httpClient);
            Fees          = new FeesClient(_httpClient);
            Invoices      = new InvoicesClient(BuildHttpClient(_urlInvoicing, _userKey, "application/vnd.api+json"));
            Payments      = new PaymentsClient(_httpClient);
            Subscriptions = new SubscriptionsClient(_httpClient);
        }
Example #23
0
        public async Task SubmitPaymentUnauthorized()
        {
            var paymentRequest = PaymentsControllerTests.GetPaymentRequest();

            PaymentClient = new PaymentsClient(HttpClient.BaseAddress.ToString(), HttpClient, () => "wrong-token");
            try
            {
                await PaymentClient.PostPaymentAsync(paymentRequest);

                Assert.Fail();
            }
            catch (ApiException e)
            {
                Assert.AreEqual(401, e.StatusCode);
            }
        }
Example #24
0
 public SetupController(AccountsClient accountsClient,
                        CardsClient cardsClient,
                        LoansClient loansClient,
                        PaymentsClient paymentsClient,
                        TransactionsClient transactionsClient,
                        UsersClient usersClient,
                        Mapper mapper)
 {
     this.accountsClient     = accountsClient;
     this.cardsClient        = cardsClient;
     this.loansClient        = loansClient;
     this.paymentsClient     = paymentsClient;
     this.transactionsClient = transactionsClient;
     this.usersClient        = usersClient;
     this.mapper             = mapper;
 }
        public void CanGetDataBetweenTwoDates()
        {
            var clientConfiguration = GetDefaultDataClientConfiguration();

            var dataClient = new JustGivingDataClient(clientConfiguration);

            CreatePaymentsClient(dataClient);

            var startDate = TestContext.StartDate;
            var endDate   = startDate.AddMonths(3);

            var response = PaymentsClient.RetrievePaymentsBetween(startDate, endDate);

            Assert.IsNotNull(response);
            Assert.That(response.Count(), Is.GreaterThan(0));
            Assert.That(response.FirstOrDefault(i => i.PaymentDate > endDate), Is.Null);
            Assert.That(response.FirstOrDefault(i => i.PaymentDate < startDate), Is.Null);
        }
        public async Task CallsCancelPaymentEndpoint()
        {
            // given
            var subject = new PaymentsClient(_clientConfiguration);

            var request = new CancelPaymentRequest
            {
                Id = "PM12345678"
            };

            // when
            await subject.CancelAsync(request);

            // then
            _httpTest
            .ShouldHaveCalled("https://api.gocardless.com/payments/PM12345678/actions/cancel")
            .WithVerb(HttpMethod.Post);
        }
        public void CancelPaymentRequestIdIsNullOrWhiteSpaceThrows(string id)
        {
            // given
            var subject = new PaymentsClient(_clientConfiguration);

            var request = new CancelPaymentRequest
            {
                Id = id
            };

            // when
            AsyncTestDelegate test = () => subject.CancelAsync(request);

            // then
            var ex = Assert.ThrowsAsync <ArgumentException>(test);

            Assert.That(ex.ParamName, Is.EqualTo(nameof(request.Id)));
        }
        public async Task CallsCreatePaymentEndpoint()
        {
            // given
            var subject = new PaymentsClient(_clientConfiguration);

            var request = new CreatePaymentRequest
            {
                IdempotencyKey = Guid.NewGuid().ToString()
            };

            // when
            await subject.CreateAsync(request);

            // then
            _httpTest
            .ShouldHaveCalled("https://api.gocardless.com/payments")
            .WithHeader("Idempotency-Key")
            .WithVerb(HttpMethod.Post);
        }
        public async Task CallsGetPaymentsEndpointUsingRequest()
        {
            // given
            var subject = new PaymentsClient(_clientConfiguration);

            var request = new GetPaymentsRequest
            {
                Before = "before test",
                After  = "after test",
                Limit  = 5
            };

            // when
            await subject.GetPageAsync(request);

            // then
            _httpTest
            .ShouldHaveCalled("https://api.gocardless.com/payments?before=before%20test&after=after%20test&limit=5")
            .WithVerb(HttpMethod.Get);
        }
Example #30
0
        public GoCardlessClient(ClientConfiguration configuration)
        {
            _configuration = configuration;

            BankDetailsLookups    = new BankDetailsLookupsClient(configuration);
            CreditorBankAccounts  = new CreditorBankAccountsClient(configuration);
            Creditors             = new CreditorsClient(configuration);
            CustomerBankAccounts  = new CustomerBankAccountsClient(configuration);
            CustomerNotifications = new CustomerNotificationsClient(configuration);
            Customers             = new CustomersClient(configuration);
            Events = new EventsClient(configuration);
            MandateImportEntries = new MandateImportEntriesClient(configuration);
            MandateImports       = new MandateImportsClient(configuration);
            MandatePdfs          = new MandatePdfsClient(configuration);
            Mandates             = new MandatesClient(configuration);
            Payments             = new PaymentsClient(configuration);
            PayoutItems          = new PayoutItemsClient(configuration);
            Payouts       = new PayoutsClient(configuration);
            RedirectFlows = new RedirectFlowsClient(configuration);
            Refunds       = new RefundsClient(configuration);
            Subscriptions = new SubscriptionsClient(configuration);
        }