Example #1
0
        public async Task <IActionResult> ProcessPaymentAsync(string nonce)
        {
            try
            {
                Square.Environment environment = appSettings.Environment == "sandbox" ?
                                                 Square.Environment.Sandbox : Square.Environment.Production;

                // Build base client
                SquareClient client = new SquareClient.Builder()
                                      .Environment(environment)
                                      .AccessToken(this.appSettings.AccessToken)
                                      .Build();

                IPaymentsApi         PaymentsApi  = client.PaymentsApi;
                CreatePaymentRequest request_body = new CreatePaymentRequest(nonce, this.NewIdempotencyKey(), new Money(100, "USD"));

                CreatePaymentResponse responce = await PaymentsApi.CreatePaymentAsync(request_body);

                if (responce?.Payment?.Status == "COMPLETED")
                {
                    //this.UpdateCart(new CartModel());
                    return(this.Ok());
                }
                else
                {
                    return(this.BadRequest($"STATUS: {responce?.Payment?.Status}"));
                }
            }
            catch (Exception ex)
            {
                return(this.BadRequest($"PaymentError: { ex.Message }"));
            }
        }
Example #2
0
 public PaymentController(
     IPaymentsApi paymentsApi,
     CheckoutRepository checkoutRepository,
     PaymentRepository paymentRepository,
     IamportHttpClientOptions clientOptions)
 {
     if (paymentsApi == null)
     {
         throw new ArgumentNullException(nameof(paymentsApi));
     }
     if (checkoutRepository == null)
     {
         throw new ArgumentNullException(nameof(checkoutRepository));
     }
     if (paymentRepository == null)
     {
         throw new ArgumentNullException(nameof(paymentRepository));
     }
     if (clientOptions == null)
     {
         throw new ArgumentNullException(nameof(clientOptions));
     }
     this.paymentsApi        = paymentsApi;
     this.checkoutRepository = checkoutRepository;
     this.paymentRepository  = paymentRepository;
     iamportId = clientOptions.IamportId;
 }
        public void OnPost()
        {
            string       nonce       = Request.Form["nonce"];
            IPaymentsApi PaymentsApi = client.PaymentsApi;
            // Every payment you process with the SDK must have a unique idempotency key.
            // If you're unsure whether a particular payment succeeded, you can reattempt
            // it with the same idempotency key without worrying about double charging
            // the buyer.
            string uuid = NewIdempotencyKey();

            // Monetary amounts are specified in the smallest unit of the applicable currency.
            // This amount is in cents. It's also hard-coded for $1.00,
            // which isn't very useful.
            Money amount = new Money.Builder()
                           .Amount(500L)
                           .Currency("USD")
                           .Build();

            // To learn more about splitting payments with additional recipients,
            // see the Payments API documentation on our [developer site]
            // (https://developer.squareup.com/docs/payments-api/overview).
            CreatePaymentRequest createPaymentRequest = new CreatePaymentRequest.Builder(nonce, uuid, amount)
                                                        .Note("From Square Sample Csharp App")
                                                        .Build();

            try
            {
                CreatePaymentResponse response = PaymentsApi.CreatePayment(createPaymentRequest);
                this.ResultMessage = "Payment complete! " + response.Payment.Note;
            }
            catch (ApiException e)
            {
                this.ResultMessage = e.Message;
            }
        }
 private void InitialiseClients()
 {
     HttpChannel = new HttpChannel(_dataClientConfiguration, _httpClient);
     _payment = new PaymentsApi(HttpChannel);
     _pages = new PagesApi(HttpChannel);
     _customCodes = new CustomCodesApi(HttpChannel);
 }
 public PaymentController(
     IPaymentsApi paymentsApi,
     CheckoutRepository checkoutRepository,
     PaymentRepository paymentRepository,
     IamportHttpClientOptions clientOptions)
 {
     if (paymentsApi == null)
     {
         throw new ArgumentNullException(nameof(paymentsApi));
     }
     if (checkoutRepository == null)
     {
         throw new ArgumentNullException(nameof(checkoutRepository));
     }
     if (paymentRepository == null)
     {
         throw new ArgumentNullException(nameof(paymentRepository));
     }
     if (clientOptions == null)
     {
         throw new ArgumentNullException(nameof(clientOptions));
     }
     this.paymentsApi = paymentsApi;
     this.checkoutRepository = checkoutRepository;
     this.paymentRepository = paymentRepository;
     iamportId = clientOptions.IamportId;
 }
Example #6
0
 private void InitialiseClients()
 {
     HttpChannel  = new HttpChannel(_dataClientConfiguration, _httpClient);
     _payment     = new PaymentsApi(HttpChannel);
     _pages       = new PagesApi(HttpChannel);
     _customCodes = new CustomCodesApi(HttpChannel);
 }
 public FamilyListService(ICustomersApi customersApi, IAccountsApi accountsApi, ITransactionsApi transactionsApi, IFamilyDb familyTaskDb, IFamilyAccountDb accountDb, IPaymentsApi paymentsApi)
 {
     _customersApi    = customersApi;
     _accountsApi     = accountsApi;
     _transactionsApi = transactionsApi;
     _familyTaskDb    = familyTaskDb;
     _accountDb       = accountDb;
     _paymentsApi     = paymentsApi;
 }
Example #8
0
        public IActionResult Paid()
        {
            Square.Environment environment = this.appSettings.Environment == "sandbox" ?
                                             Square.Environment.Sandbox : Square.Environment.Production;

            // Build base client
            SquareClient client = new SquareClient.Builder()
                                  .Environment(environment)
                                  .AccessToken(this.appSettings.AccessToken)
                                  .Build();


            string       nonce       = Request.Form["nonce"];
            IPaymentsApi PaymentsApi = client.PaymentsApi;
            // Every payment you process with the SDK must have a unique idempotency key.
            // If you're unsure whether a particular payment succeeded, you can reattempt
            // it with the same idempotency key without worrying about double charging
            // the buyer.
            string uuid = this.NewIdempotencyKey();

            // Monetary amounts are specified in the smallest unit of the applicable currency.
            // This amount is in cents. It's also hard-coded for $1.00,
            // which isn't very useful.
            Money amount = new Money.Builder()
                           .Amount(500L)
                           .Currency("USD")
                           .Build();

            // To learn more about splitting payments with additional recipients,
            // see the Payments API documentation on our [developer site]
            // (https://developer.squareup.com/docs/payments-api/overview).
            CreatePaymentRequest createPaymentRequest = new CreatePaymentRequest.Builder(nonce, uuid, amount)
                                                        .Note("From Square Visit Cart App")
                                                        .Build();

            try
            {
                CreatePaymentResponse response = PaymentsApi.CreatePayment(createPaymentRequest);
                PaymentResultModel    model    = new PaymentResultModel
                {
                    ResultMessage = "Payment complete! " + response.Payment.Note
                };

                return(View(model));
            }
            catch (ApiException ex)
            {
                return(View("PaymentError", new ErrorViewModel {
                    Message = ex.Message
                }));
            }
        }
Example #9
0
 public DirectPaymentController(
     IPaymentsApi paymentsApi,
     ISubscribeApi subscribeApi,
     CheckoutRepository checkoutRepository,
     PaymentRepository paymentRepository,
     IamportHttpClientOptions clientOptions)
 {
     this.paymentsApi        = paymentsApi ?? throw new ArgumentNullException(nameof(paymentsApi));
     this.subscribeApi       = subscribeApi ?? throw new ArgumentNullException(nameof(subscribeApi));
     this.checkoutRepository = checkoutRepository ?? throw new ArgumentNullException(nameof(checkoutRepository));
     this.paymentRepository  = paymentRepository ?? throw new ArgumentNullException(nameof(paymentRepository));
     if (clientOptions == null)
     {
         throw new ArgumentNullException(nameof(clientOptions));
     }
     iamportId = clientOptions.IamportId;
 }
 public CheckoutApiClient(IPaymentsApi client)
 {
     this.Client = client;
 }