コード例 #1
0
        static void TestPaymentService(string accessToken)
        {
            L("Payment Service Testing");
            GlobeLabs api = new GlobeLabs(accessToken);

            var payload = new PaymentPayload
            {
                Amount        = "0.00",
                Description   = "Charging API",
                Number        = "9171234567",
                ReferenceCode = "45750000001"
            };

            /*
             * TIPS for Reference Code:
             * - Fetch the latest count for payment reference in your database
             * - Store it in a variable or update your table that holds the last reference count
             * - IMPORTANT: Make sure that your reference code is unique. Bad Request will occur if code is repeating
             */
            // If your short code is 21554575, then your reference code prefix is 4575 + 7digit numbers

            var result = api.Charge(payload);

            L("Data: " + result);
        }
コード例 #2
0
        public void MakePayment(PaymentMethod method, Order product, PaymentPayload paymentpayload)
        {
            PaymentGatewayFactory factory = new PaymentGatewayFactory();
            // this.gateway = factory.CreatePaymentGateway(method);

            //this.gateway.MakePayment(product,paymentpayload);
        }
コード例 #3
0
        public virtual async Task <bool?> ChargeCardAsync(PaymentPayload payload)
        {
            var client = httpClientFactory.CreateClient(Type.ToString());
            var body   = JsonSerializer.Serialize(payload);

            using var content = new StringContent(body, Encoding.UTF8, "application/json");

            logger.LogInformation("Payload built for request: {0}", body);
            logger.LogInformation("Request Url: {0}", GatewayEndpoint);
            logger.LogInformation("Request Headers: {0}", client.DefaultRequestHeaders);

            try
            {
                var response = await client.PostAsync(GatewayEndpoint, content);

                var result = await response.Content.ReadAsStringAsync();

                logger.LogInformation("Response From {0} Gateway: {1}", Type, result);

                response.EnsureSuccessStatusCode();

                return(ProcessResponse(result));
            }
            catch (Exception e)
            {
                logger.LogError(e, "Call to {0} Gateway failed", Type);
                return(null);
            }
        }
コード例 #4
0
        private static PaymentType DerivePaymentType(PaymentPayload payload)
        {
            if (payload.Amount <= 20)
            {
                return(PaymentType.Cheap);
            }

            return(payload.Amount > 500 ? PaymentType.Premium : PaymentType.Expensive);
        }
コード例 #5
0
 public static Payment ConvertFrom(PaymentPayload payload)
 {
     return(new Payment
     {
         Amount = payload.Amount, CardHolder = payload.CardHolder,
         CreditCardNumber = payload.CreditCardNumber, ExpirationDate = payload.ExpirationDate,
         SecurityCode = payload.SecurityCode, State = PaymentResult.Pending
     });
 }
コード例 #6
0
        private async Task <bool?> HandleRetryOnCheapGateway(Guid paymentId, PaymentPayload payload)
        {
            var result = await ProcessCardDebitAsync(paymentId, PaymentType.Cheap, payload);

            if (!result.HasValue || !result.Value)
            {
                logger.LogError("Could Not Process Payment with Either Cheap Or Expensive Gateway");
            }
            return(result);
        }
コード例 #7
0
ファイル: Sage50Api.cs プロジェクト: valentin78/Apination
        public void CreatePayment(PaymentPayload paymentPayload)
        {
            UpsertInvoice(paymentPayload.invoice);

            foreach (var payment in paymentPayload.payments)
            {
                var sagePayment = CompanyContext.Factories.PaymentFactory.Create();
                sagePayment.VendorReference = UpsertVendor(payment.Vendor);
                sagePayment.PopulateFromModel(CompanyContext, payment);
            }
        }
コード例 #8
0
        public void Test_PaymentPayload()
        {
            var payload = new PaymentPayload
            {
                Amount         = 500M, CreditCardNumber = CCNs.First(), CardHolder = "Olawale Lawal",
                ExpirationDate = DateTime.Now.AddYears(2)
            };

            var result = Validator.TryValidateObject(payload, new ValidationContext(payload, null, null), null, true);

            Assert.True(result);
        }
コード例 #9
0
        public async Task <ObjectResource <PaymentResource> > ProcessAsync(PaymentPayload payload)
        {
            logger.LogInformation("Starting Unit Of Work For Payment Processing");
            await unitOfWork.StartAsync();

            var payment = PaymentMapper.ConvertFrom(payload);

            await unitOfWork.PaymentRepository.CreateNewAsync(payment);

            var paymentType = DerivePaymentType(payload);

            logger.LogInformation("Derived Payment Type of {0} for {1}", paymentType, payload.Amount);

            var result = await HandlePaymentProcessingAsync(payment, paymentType, payload);

            await HandlePaymentResponse(payment, result);

            return(result);
        }
コード例 #10
0
 public async void MakePayment(Order value, PaymentPayload paymentpayload)
 {
     //var order = (OrderToPay)paymentpayload.Paymentpayload;
     var b2c = new
     {
         InitiatorName      = "testapi",
         SecurityCredential = securitycredential,
         CommandID          = "BusinessPayment",
         Amount             = value.Amount,
         PartyA             = "600438",
         PartyB             = "der",
         Remarks            = "Payment out",
         QueueTimeOutURL    = "",
         ResultURL          = "",
         Occassion          = "payout"
     };
     //MpesaRepository mpesaFactory = new MpesaRepository();
     //var response = await mpesaFactory.TryPostToMpesa(url, b2c);
 }
コード例 #11
0
        private async Task <ObjectResource <PaymentResource> > HandlePaymentProcessingAsync(Payment payment, PaymentType paymentType, PaymentPayload payload)
        {
            var result = await ProcessCardDebitAsync(payment.Id, paymentType, payload);

            if (paymentType == PaymentType.Expensive && (!result.HasValue || !result.Value))
            {
                result = await HandleRetryOnCheapGateway(payment.Id, payload);
            }

            if (result.HasValue && result.Value)
            {
                payment.State = PaymentResult.Processed;
                logger.LogInformation("Successfully processed payment");
                return(new ObjectResource <PaymentResource>
                {
                    Message = "Payment Successfully processed", ResponseType = ResponseType.Created,
                    Status = result.Value
                });
            }

            payment.State = result.HasValue ? PaymentResult.Failed : PaymentResult.Pending;

            logger.LogInformation("could not process payment");
            return(new ObjectResource <PaymentResource>
            {
                Message = "Payment Could Not Be Processed", ResponseType = ResponseType.ServiceError,
                Status = result.HasValue
            });
        }
コード例 #12
0
        private async Task <bool?> ProcessCardDebitAsync(Guid paymentId, PaymentType paymentType, PaymentPayload payload)
        {
            var paymentGateway = await ResolvePaymentGateway(paymentId, paymentType);

            if (paymentGateway is null)
            {
                return(null);
            }

            var result = await paymentGateway.ChargeCardAsync(payload);

            var isSuccessful = result.HasValue && result.Value;
            var errorMessage = result.HasValue ? "Could Not Debit Card" : "Service Error Occurred On Gateway";

            await AddPaymentState(paymentId, paymentGateway.Type, isSuccessful,
                                  isSuccessful?string.Empty : errorMessage);

            return(result);
        }
コード例 #13
0
        public async Task <ActionResult <ObjectResource <PaymentResource> > > ProcessPayment([FromBody] PaymentPayload payload)
        {
            var result = await paymentService.ProcessAsync(payload);

            return(HandleResponse(nameof(GetPayment), new { paymentId = result.Data?.PaymentId }, result));
        }
コード例 #14
0
 // [MessageHandlers.JWTAuthHandler]
 public PaymentResponse MakePayment(PaymentPayload payment)
 {
     return(new Pay().NewRecord(payment));
 }
コード例 #15
0
        public void Test_PaymentInvalidPayload(PaymentPayload payload)
        {
            var result = Validator.TryValidateObject(payload, new ValidationContext(payload, null, null), null, true);

            Assert.IsFalse(result);
        }