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)); }
public override async Task <Empty> BatchRepayInstalments(BatchRepayInstalmentsRequest request, ServerCallContext context) { var paymentsToFinish = RepayInstalments(request); if (paymentsToFinish.Any()) { var cancelPaymentsRequest = new CancelPaymentsRequest { Ids = { paymentsToFinish } }; await paymentsClient.CancelAsync(cancelPaymentsRequest, context.RequestHeaders.SelectCustom()); } return(new Empty()); }
public void CancelPaymentRequestIsNullThrows() { // given var subject = new PaymentsClient(_clientConfiguration); CancelPaymentRequest request = null; // when AsyncTestDelegate test = () => subject.CancelAsync(request); // then var ex = Assert.ThrowsAsync <ArgumentNullException>(test); Assert.That(ex.ParamName, Is.EqualTo(nameof(request))); }
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 CreatesAndCancelsPaymentForMerchant() { var accessToken = Environment.GetEnvironmentVariable("GoCardlessMerchantAccessToken"); var configuration = ClientConfiguration.ForSandbox(accessToken); var resourceFactory = new ResourceFactory(configuration); var creditor = await resourceFactory.Creditor(); var mandatesClient = new MandatesClient(configuration); var mandate = (await mandatesClient.GetPageAsync()).Items.First(); // given var createRequest = new CreatePaymentRequest { Amount = 500, AppFee = 12, 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", } }; var subject = new PaymentsClient(configuration); // when 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)); }