private CreateCheckoutRequest GetCheckoutRequest(PaymentRequest request)
        {
            string uuid = Guid.NewGuid().ToString();
            // square APi  货币的最小面额指定。例如,美元金额以美分指定,https://developer.squareup.com/docs/build-basics/working-with-monetary-amounts
            var amount = new Money {
                Amount = SquareCommon.GetSquareAmount(request.TotalAmount), Currency = request.Currency
            };

            return(new CreateCheckoutRequest
            {
                IdempotencyKey = uuid,
                RedirectUrl = Setting.RedirectURL,
                Order = new CreateOrderRequest
                {
                    LineItems = new List <CreateOrderRequestLineItem> {
                        new CreateOrderRequestLineItem
                        {
                            BasePriceMoney = amount,
                            Name = request.Name,
                            Quantity = "1",
                            Note = request.Description
                        }
                    }
                }
            });
        }
예제 #2
0
        public IPaymentResponse GetHtmlDetail(RenderContext context)
        {
            if (this.Setting == null)
            {
                return(null);
            }

            // todo 需要转换为货币的最低单位
            // square APi 货币的最小面额指定。例如,美元金额以美分指定,https://developer.squareup.com/docs/build-basics/working-with-monetary-amounts
            var amount = new Money {
                Amount = SquareCommon.GetSquareAmount(decimal.Parse(context.Request.Get("totalAmount"))), Currency = context.Request.Get("currency")
            };

            var squareResponseNonce = context.Request.Get("nonce");

            var result = PaymentsApi.CreatPayment(squareResponseNonce, amount, Setting);

            var deserializeResult = JsonConvert.DeserializeObject <PaymentResponse>(result);

            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"));
            }
        }
예제 #3
0
 public PaymentCallback Notify(RenderContext context)
 {
     return(SquareCommon.ProcessNotify(context));
 }