Пример #1
0
        /// <summary>
        /// Captures an authorised charge.
        /// </summary>
        public HttpResponse <Capture> CaptureCharge(string chargeId, ChargeCapture requestModel)
        {
            if (!chargeId.StartsWith("charge_"))
            {
                chargeId = "charge_" + chargeId;
            }

            var request = new RestRequest(Endpoints.CaptureCharge, Method.POST);

            request.AddUrlSegment("chargeId", chargeId);
            request.RequestFormat = DataFormat.Json;
            request.AddBody(requestModel);
            return(Execute <Capture>(request));
        }
Пример #2
0
        public Capture capturePayment(string chargeId)
        {
            // cardChargCapture is optional. either we just pass ChargeCapture alias .Only chargeId required.

            var cardChargCapture = new ChargeCapture()
            {
                Value    = "1",
                Products = new List <Product>()
                {
                    new Product {
                        Name         = "ipad 3",
                        Price        = 1,
                        Quantity     = 1,
                        ShippingCost = 10.5M,
                        Description  = "Gold edition",
                        Image        = "http://goofle.com/?id=12345",
                        Sku          = "TR12345", TrackingUrl = "http://tracket.com?id=123456"
                    }
                }
            };
            HttpClient client = new HttpClient();

            client.DefaultRequestHeaders.Clear();
            client.DefaultRequestHeaders.Add("Authorization", "sk_test_b2ce2577-0c3e-44f3-91e9-f14ea499cfce");
            client.DefaultRequestHeaders.Accept.Add(
                new MediaTypeWithQualityHeaderValue("application/json"));

            var    response = client.PostAsJsonAsync("https://sandbox.checkout.com/api2/v2/charges/" + chargeId + "/capture", cardChargCapture).Result;
            string res      = "";

            if (response.IsSuccessStatusCode)
            {
                using (HttpContent content = response.Content)
                {
                    // ... Read the string.
                    Task <string> result = content.ReadAsStringAsync();
                    res = result.Result;
                    var captureResponce = JsonConvert.DeserializeObject <CheckoutJSImplementation.Models.Capture>(res);
                    return(captureResponce);
                }
            }
            else
            {
                Task <string> result = response.Content.ReadAsStringAsync();
                res = result.Result;
            }
            return(null);
        }
    protected void but_captureCharge_Click(object sender, EventArgs e)
    {
        // Create payload
        var captureChargeRequestModel = new ChargeCapture()
        {
            Description = "capture charge",
            TrackId     = "TRK12345",
            Value       = "100"
        };

        try
        {
            // Create APIClient instance with your secret key
            ckoAPIClient = new APIClient();

            // Submit your request and receive an apiResponse
            HttpResponse <Capture> apiResponse = ckoAPIClient.ChargeService.CaptureCharge(tb_authChargeId.Text, captureChargeRequestModel);

            if (!apiResponse.HasError)
            {
                // Access the response object retrieved from the api
                var capture = apiResponse.Model;

                tb_captureChargeRsp.Text = String.Format("Status:\n {0}! \n\nCapture ID:\n {1} \n\nCapture Response Code:\n {2} \n\nCapture Response Message:\n {3} \n\nCaptured Value:\n {4} \n\nJSON Response: \n {5}",
                                                         capture.Status, capture.Id, capture.ResponseCode, capture.ResponseMessage, capture.Value, apiResponse.FullJsonResponse);
            }
            else
            {
                // Api has returned an error object. You can access the details in the error property of the apiResponse.
                // apiResponse.error
                tb_captureChargeRsp.Text = string.Format("Message:/n{0} Error Code:/n{1} ", apiResponse.Error.Message, apiResponse.Error.ErrorCode);
            }
        }
        catch (Exception exc)
        {
            //... Handle exception
        }
    }
Пример #4
0
        /// <summary>
        /// Captures an authorised charge.
        /// </summary>
        public HttpResponse <Capture> CaptureCharge(string chargeId, ChargeCapture requestModel)
        {
            var captureChargesApiUri = string.Format(ApiUrls.CaptureCharge, chargeId);

            return(new ApiHttpClient().PostRequest <Capture>(captureChargesApiUri, AppSettings.SecretKey, requestModel));
        }
Пример #5
0
        public Task <HttpResponse <Capture> > CaptureChargeAsync(string chargeId, ChargeCapture requestModel)
        {
            var captureChargesApiUri = string.Format(_configuration.ApiUrls.CaptureCharge, chargeId);

            return(_apiHttpClient.PostRequest <Capture>(captureChargesApiUri, _configuration.SecretKey, requestModel));
        }
Пример #6
0
 public HttpResponse <Capture> CaptureCharge(string chargeId, ChargeCapture requestModel)
 {
     return(_chargeServiceAsync.CaptureChargeAsync(chargeId, requestModel).Result);
 }