internal async Task <Mandate> CreateMandateFor( Creditor creditor, Customer customer, CustomerBankAccount customerBankAccount) { var request = new CreateMandateRequest { Links = new CreateMandateLinks { Creditor = creditor.Id, CustomerBankAccount = customerBankAccount.Id }, Metadata = new Dictionary <string, string> { ["Key1"] = "Value1", ["Key2"] = "Value2", ["Key3"] = "Value3", }, Scheme = Scheme.Bacs }; var mandatesClient = new MandatesClient(_clientConfiguration); return((await mandatesClient.CreateAsync(request)).Item); }
public void CreateMandateRequestIsNullThrows() { // given var subject = new MandatesClient(_clientConfiguration); CreateMandateRequest request = null; // when AsyncTestDelegate test = () => subject.CreateAsync(request); // then var ex = Assert.ThrowsAsync <ArgumentNullException>(test); Assert.That(ex.ParamName, Is.EqualTo(nameof(request))); }
public async void Example() { #pragma warning disable 0168 using (Client client = GetClient()) { BankAccountIban bankAccountIban = new BankAccountIban(); bankAccountIban.Iban = "DE46720200700359736690"; MandateContactDetails contactDetails = new MandateContactDetails(); contactDetails.EmailAddress = "*****@*****.**"; MandateAddress mandateAddress = new MandateAddress(); mandateAddress.City = "Monumentenvallei"; mandateAddress.CountryCode = "NL"; mandateAddress.Street = "Woestijnweg"; mandateAddress.Zip = "1337XD"; MandatePersonalName name = new MandatePersonalName(); name.FirstName = "Wile"; name.Surname = "Coyote"; MandatePersonalInformation personalInformation = new MandatePersonalInformation(); personalInformation.Name = name; personalInformation.Title = "Miss"; MandateCustomer customer = new MandateCustomer(); customer.BankAccountIban = bankAccountIban; customer.CompanyName = "Acme labs"; customer.ContactDetails = contactDetails; customer.MandateAddress = mandateAddress; customer.PersonalInformation = personalInformation; CreateMandateRequest body = new CreateMandateRequest(); body.Customer = customer; body.CustomerReference = "idonthaveareference"; body.Language = "nl"; body.RecurrenceType = "UNIQUE"; body.SignatureType = "UNSIGNED"; CreateMandateResponse response = await client.Merchant("merchantId").Mandates().Create(body); } #pragma warning restore 0168 }
/// <summary> /// Resource /{merchantId}/mandates /// <a href="https://epayments-api.developer-ingenico.com/s2sapi/v1/en_US/dotnet/mandates/create.html">Create mandate</a> /// </summary> /// <param name="body">CreateMandateRequest</param> /// <param name="context">CallContext</param> /// <returns>CreateMandateResponse</returns> /// <exception cref="ValidationException">if the request was not correct and couldn't be processed (HTTP status code BadRequest)</exception> /// <exception cref="AuthorizationException">if the request was not allowed (HTTP status code Forbidden)</exception> /// <exception cref="IdempotenceException">if an idempotent request caused a conflict (HTTP status code Conflict)</exception> /// <exception cref="ReferenceException">if an object was attempted to be referenced that doesn't exist or has been removed, /// or there was a conflict (HTTP status code NotFound, Conflict or Gone)</exception> /// <exception cref="GlobalCollectException">if something went wrong at the Ingenico ePayments platform, /// the Ingenico ePayments platform was unable to process a message from a downstream partner/acquirer, /// or the service that you're trying to reach is temporary unavailable (HTTP status code InternalServerError, BadGateway or ServiceUnavailable)</exception> /// <exception cref="ApiException">if the Ingenico ePayments platform returned any other error</exception> public async Task <CreateMandateResponse> Create(CreateMandateRequest body, CallContext context = null) { string uri = InstantiateUri("/{apiVersion}/{merchantId}/mandates", null); try { return(await _communicator.Post <CreateMandateResponse>( uri, ClientHeaders, null, body, context)); } catch (ResponseException e) { object errorObject = _communicator.Marshaller.Unmarshal <ErrorResponse>(e.Body); throw CreateException(e.StatusCode, e.Body, errorObject, context); } }
public async Task CallsCreateMandateEndpoint() { // given var subject = new MandatesClient(_clientConfiguration); var request = new CreateMandateRequest { IdempotencyKey = Guid.NewGuid().ToString() }; // when await subject.CreateAsync(request); // then _httpTest .ShouldHaveCalled("https://api.gocardless.com/mandates") .WithHeader("Idempotency-Key") .WithVerb(HttpMethod.Post); }
public async Task CreatesConflictingMandate() { // given var request = new CreateMandateRequest { Links = new CreateMandateLinks { Creditor = _creditor.Id, CustomerBankAccount = _customerBankAccount.Id }, Metadata = new Dictionary <string, string> { ["Key1"] = "Value1", ["Key2"] = "Value2", ["Key3"] = "Value3", }, Scheme = Scheme.Bacs, }; var subject = new MandatesClient(_clientConfiguration); // when await subject.CreateAsync(request); var result = await subject.CreateAsync(request); // then Assert.That(result.Item, Is.Not.Null); Assert.That(result.Item.Id, Is.Not.Null); Assert.That(result.Item.CreatedAt, Is.Not.EqualTo(default(DateTimeOffset))); Assert.That(result.Item.Links.Creditor, Is.EqualTo(_creditor.Id)); Assert.That(result.Item.Links.CustomerBankAccount, Is.EqualTo(_customerBankAccount.Id)); Assert.That(result.Item.Metadata, Is.EqualTo(request.Metadata)); Assert.That(result.Item.NextPossibleChargeDate, Is.Not.Null.And.Not.EqualTo(default(DateTime))); Assert.That(result.Item.Scheme, Is.EqualTo(request.Scheme)); Assert.That(result.Item.Status, Is.Not.Null.And.Not.EqualTo(MandateStatus.Cancelled)); }
/// <summary> /// Resource /{merchantId}/mandates/{uniqueMandateReference} /// <a href="https://epayments-api.developer-ingenico.com/s2sapi/v1/en_US/dotnet/mandates/createWithMandateReference.html">Create mandate with mandatereference</a> /// </summary> /// <param name="uniqueMandateReference">string</param> /// <param name="body">CreateMandateRequest</param> /// <param name="context">CallContext</param> /// <returns>CreateMandateResponse</returns> /// <exception cref="ValidationException">if the request was not correct and couldn't be processed (HTTP status code BadRequest)</exception> /// <exception cref="AuthorizationException">if the request was not allowed (HTTP status code Forbidden)</exception> /// <exception cref="IdempotenceException">if an idempotent request caused a conflict (HTTP status code Conflict)</exception> /// <exception cref="ReferenceException">if an object was attempted to be referenced that doesn't exist or has been removed, /// or there was a conflict (HTTP status code NotFound, Conflict or Gone)</exception> /// <exception cref="GlobalCollectException">if something went wrong at the Ingenico ePayments platform, /// the Ingenico ePayments platform was unable to process a message from a downstream partner/acquirer, /// or the service that you're trying to reach is temporary unavailable (HTTP status code InternalServerError, BadGateway or ServiceUnavailable)</exception> /// <exception cref="ApiException">if the Ingenico ePayments platform returned any other error</exception> public async Task <CreateMandateResponse> CreateWithMandateReference(string uniqueMandateReference, CreateMandateRequest body, CallContext context = null) { IDictionary <string, string> pathContext = new Dictionary <string, string>(); pathContext.Add("uniqueMandateReference", uniqueMandateReference); string uri = InstantiateUri("/{apiVersion}/{merchantId}/mandates/{uniqueMandateReference}", pathContext); try { return(await _communicator.Put <CreateMandateResponse>( uri, ClientHeaders, null, body, context)); } catch (ResponseException e) { object errorObject = _communicator.Marshaller.Unmarshal <ErrorResponse>(e.Body); throw CreateException(e.StatusCode, e.Body, errorObject, context); } }
public async Task CreatesCancelsAndReinstatesMandate() { // given var createRequest = new CreateMandateRequest { Links = new CreateMandateLinks { Creditor = _creditor.Id, CustomerBankAccount = _customerBankAccount.Id }, Metadata = new Dictionary <string, string> { ["Key1"] = "Value1", ["Key2"] = "Value2", ["Key3"] = "Value3", }, Reference = DateTime.Now.ToString("yyyyMMddhhmmss"), Scheme = Scheme.Bacs }; var subject = new MandatesClient(_clientConfiguration); // when var creationResult = await subject.CreateAsync(createRequest); var cancelRequest = new CancelMandateRequest { Id = creationResult.Item.Id, Metadata = new Dictionary <string, string> { ["Key4"] = "Value4", ["Key5"] = "Value5", ["Key6"] = "Value6", }, }; var cancellationResult = await subject.CancelAsync(cancelRequest); var reinstateRequest = new ReinstateMandateRequest { Id = creationResult.Item.Id, Metadata = new Dictionary <string, string> { ["Key7"] = "Value7", ["Key8"] = "Value8", ["Key9"] = "Value9", }, }; var reinstateResult = (await subject.ReinstateAsync(reinstateRequest)); // then Assert.That(creationResult.Item, Is.Not.Null); Assert.That(creationResult.Item.Id, Is.Not.Null); Assert.That(creationResult.Item.CreatedAt, Is.Not.EqualTo(default(DateTimeOffset))); Assert.That(creationResult.Item.Links.Creditor, Is.EqualTo(_creditor.Id)); Assert.That(creationResult.Item.Links.CustomerBankAccount, Is.EqualTo(_customerBankAccount.Id)); Assert.That(creationResult.Item.Metadata, Is.EqualTo(createRequest.Metadata)); Assert.That(creationResult.Item.NextPossibleChargeDate, Is.Not.Null.And.Not.EqualTo(default(DateTime))); Assert.That(creationResult.Item.Reference, Is.Not.Null.And.EqualTo(createRequest.Reference)); Assert.That(creationResult.Item.Scheme, Is.EqualTo(createRequest.Scheme)); Assert.That(creationResult.Item.Status, Is.Not.Null.And.Not.EqualTo(MandateStatus.Cancelled)); Assert.That(cancellationResult.Item.Status, Is.EqualTo(MandateStatus.Cancelled)); Assert.That(reinstateResult.Item.Status, Is.Not.Null.And.Not.EqualTo(MandateStatus.Cancelled)); }
public static string DoMandateCreation(string createMandateStr) { Serializer ser = new Serializer(); string xmlOutputData = string.Empty; string responseCode = string.Empty; DateTime requestTime = DateTime.Now; CreateMandateResponse objResp = new CreateMandateResponse(); try { CreateMandateRequest obj = ser.Deserialize <CreateMandateRequest>(createMandateStr); if (obj != null) { if (!string.IsNullOrEmpty(obj.BillerID) || !string.IsNullOrEmpty(obj.BillerName) || !string.IsNullOrEmpty(obj.BillerTransId) || !string.IsNullOrEmpty(obj.AcctName) || !string.IsNullOrEmpty(obj.AcctNumber) || !string.IsNullOrEmpty(obj.BankCode)) { MandateLog mlog = new MandateLog() { AccountName = obj.AcctName, BankCode = obj.BankCode, AccountNumber = obj.AcctNumber, BillerId = obj.BillerID, BillerName = obj.BillerName, BillerTransId = obj.BillerTransId, DateCreated = DateTime.Now, HashValue = obj.HashValue, TransType = obj.TransType }; bool isSaved = MandateRepo.SaveMandate(mlog); responseCode = isSaved ? ResponseCodeMap.Successful : ResponseCodeMap.UnknownError; objResp = new CreateMandateResponse { AcctName = obj.AcctName, AcctNumber = obj.AcctNumber, BankCode = obj.BankCode, BillerID = obj.BillerID, BillerName = obj.BillerName, BillerTransId = obj.BillerTransId, MandateCode = isSaved ? mlog.MandateCode : "", TransType = obj.TransType, ResponseCode = responseCode }; } else { objResp = new CreateMandateResponse { ResponseCode = ResponseCodeMap.InvalidXml }; } } else { objResp = new CreateMandateResponse { ResponseCode = ResponseCodeMap.InvalidXml }; } xmlOutputData = ser.Serialize <CreateMandateResponse>(objResp); } catch (Exception e) { ExceptionLogRepo.SaveExceptionLog(e); xmlOutputData = ser.Serialize <CreateMandateResponse>(new CreateMandateResponse { ResponseCode = ResponseCodeMap.InvalidXml }); } DateTime responseTime = DateTime.Now; RequestResponseRepository.SaveRequestResponse("ASMX", createMandateStr, requestTime, "", xmlOutputData, responseTime); return(xmlOutputData); }