public async Task <CreatingChargesResponse> CreateChargeTask(int merchantReferenceNumber, CustomerInfo customerInfo, PaymentInfo paymentInfo, ChargeItem[] chargeItems, CancellationToken cancellationToken = default) { var parameters = new { merchantCode = _merchantCode, merchantRefNum = merchantReferenceNumber, customerProfileId = customerInfo.ProfileId, customerMobile = customerInfo.Mobile, customerEmail = customerInfo.Email, paymentMethod = paymentInfo.PaymentMethod.ToString().ToUpper(), amount = paymentInfo.Amount.ToString("F2"), currencyCode = paymentInfo.CurrencyCode, description = paymentInfo.Description, paymentExpiry = paymentInfo.PaymentExpiry, chargeItems }; var json = parameters.SignedSerialize(p => new { p.merchantCode, p.merchantRefNum, p.customerProfileId, p.paymentMethod, p.amount, Token = paymentInfo.PaymentMethod == PaymentMethod.PayAtFawry ? "" : paymentInfo.CardToken, _securityKey }); var content = new StringContent(json, Encoding.UTF8, "application/json"); var response = await _client.PostAsync($"{_baseApiUri.TrimEnd('/')}/ECommerceWeb/Fawry/payments/charge", content, cancellationToken); if (!response.IsSuccessStatusCode) { throw new ResponseException(response); } if (cancellationToken.IsCancellationRequested) { return(null); } var responseData = await response.Content.ReadAsStringAsync(); var fawryResponseData = responseData.Deserialize <CreatingChargesResponse>(); if (fawryResponseData.StatusCode == 200) { return(fawryResponseData); } throw new Exception($"{fawryResponseData.StatusDescription}") { Data = { { nameof(fawryResponseData.Type), fawryResponseData.Type }, { nameof(fawryResponseData.StatusCode), fawryResponseData.StatusCode }, { nameof(fawryResponseData.StatusDescription), fawryResponseData.StatusDescription }, } }; }
public async Task <CreatingChargesResponse> CreateChargeTask(int merchantReferenceNumber, string customerProfileId, PaymentInfo paymentInfo, ChargeItem[] chargeItems = null, CancellationToken cancellationToken = default) { return(await CreateChargeTask(merchantReferenceNumber, new CustomerInfo(customerProfileId, null, null), paymentInfo, chargeItems, cancellationToken)); }