Example #1
0
        private CreateCheckoutRequest GetCheckoutRequest(PaymentRequest request)
        {
            string uuid = Guid.NewGuid().ToString();
            // square货币的最小面额指定。https://developer.squareup.com/docs/build-basics/working-with-monetary-amounts
            var amount = new Money {
                Amount = CurrencyDecimalPlaceConverter.ToMinorUnit(request.Currency, request.TotalAmount), Currency = request.Currency
            };

            return(new CreateCheckoutRequest
            {
                IdempotencyKey = uuid,
                RedirectUrl = string.IsNullOrEmpty(request.ReturnUrl) ? Setting.RedirectURL : request.ReturnUrl,
                Order = new CreateOrderRequest
                {
                    ReferenceId = request.Id.ToString(),
                    LineItems = new List <CreateOrderRequestLineItem> {
                        new CreateOrderRequestLineItem
                        {
                            BasePriceMoney = amount,
                            Name = request.Name,
                            Quantity = "1",
                            Note = request.Description
                        }
                    }
                }
            });
        }
Example #2
0
        public IPaymentResponse Charge(PaymentRequest request)
        {
            var amount = CurrencyDecimalPlaceConverter.ToMinorUnit(request.Currency, request.TotalAmount);
            var req    = new KpSessionRequest
            {
                PurchaseCurrency = request.Currency,
                PurchaseCountry  = request.Country,
                OrderAmount      = amount,
                OrderLines       = new[]
                {
                    new KpSessionRequest.OrderLine
                    {
                        Name        = request.Name,
                        Quantity    = 1,
                        UnitPrice   = amount,
                        TotalAmount = amount
                    }
                },
            };

            var apiClient  = new KlarnaApi(Setting, request.Country);
            var kpSession  = apiClient.CreateKpSession(req);
            var urls       = GetGetMerchantUrls(request);
            var hppSession = apiClient.CreateHppSession(kpSession.SessionId, urls);

            return(new RedirectResponse(hppSession.RedirectUrl, request.Id)
            {
                paymemtMethodReferenceId = hppSession.SessionId
            });
        }
Example #3
0
        public IPaymentResponse Charge(PaymentRequest request)
        {
            //var callbackUrl = PaymentHelper.GetCallbackUrl(this, nameof(Notify), Context);
            request.Additional.TryGetValue("email", out var email);
            var req = new Smart2PayRequest
            {
                Payment = new Smart2PayPaymentBasic
                {
                    MerchantTransactionId = request.Id.ToString(),
                    Amount      = CurrencyDecimalPlaceConverter.ToMinorUnit(request.Currency, request.TotalAmount),
                    Currency    = request.Currency,
                    Description = request.Description,
                    ReturnUrl   = !string.IsNullOrWhiteSpace(request.ReturnUrl) ? request.ReturnUrl : Setting.ReturnUrl,
                    Customer    = new Smart2PayPaymentBasic.CustomerInfo
                    {
                        Email = (string)email
                    }
                }
            };

            var resp = new Smart2PayApi(Setting).CreatePayment(req);

            return(new RedirectResponse(resp.Payment.RedirectUrl, request.Id)
            {
                paymemtMethodReferenceId = resp.Payment.Id.ToString()
            });
        }
Example #4
0
        public static long FormatAmountToMinorUnits(string currency, decimal amount)
        {
            var uppperCurrency = currency.ToUpper();

            switch (uppperCurrency)
            {
            case "CVE":
            case "IDR":
                return((long)amount);

            default:
                return(CurrencyDecimalPlaceConverter.ToMinorUnit(currency, amount));
            }
        }
Example #5
0
        public IPaymentResponse CreatPayment(RenderContext context)
        {
            if (this.Setting == null)
            {
                return(null);
            }

            // square 货币的最小面额指定。https://developer.squareup.com/docs/build-basics/working-with-monetary-amounts
            var currency     = context.Request.Get("currency");
            var totalAmount  = decimal.Parse(context.Request.Get("totalAmount"));
            var requestIdStr = context.Request.Get("paymentRequestId");
            var amount       = new Money
            {
                Amount   = CurrencyDecimalPlaceConverter.ToMinorUnit(currency, totalAmount),
                Currency = currency
            };

            var deserializeResult = PaymentsApi.CreatPayment(context.Request.Get("nonce"), amount, Setting, requestIdStr);

            // 把paymentID赋值到request referenceID 为了后面 checkStatus 使用
            var  paymentRequestIdStr = context.Request.Get("paymentRequestId");
            Guid paymentRequestId;

            if (Guid.TryParse(paymentRequestIdStr, out paymentRequestId))
            {
                var request = PaymentManager.GetRequest(paymentRequestId, context);
                request.ReferenceId = deserializeResult.Payment.ID;
                PaymentManager.UpdateRequest(request, context);
            }

            if (deserializeResult.Payment.Status == "APPROVED" || deserializeResult.Payment.Status == "COMPLETED")
            {
                var res = new PaidResponse();
                res.paymemtMethodReferenceId = deserializeResult.Payment.ID;
                return(res);
            }
            else if (deserializeResult.Payment.Status == "CANCELED" || deserializeResult.Payment.Status == "FAILED")
            {
                return(new FailedResponse("FAILED"));
            }
            else
            {
                // TODO: please check.
                return(new FailedResponse("No response"));
            }
        }