public async Task <string> ApiDemo() { ApiClientAsync CheckoutClient; try { CheckoutConfiguration configuration = new CheckoutConfiguration() { SecretKey = Environment.GetEnvironmentVariable("CKO_SECRET_KEY"), DebugMode = true }; CheckoutClient = new ApiClientAsync(configuration); CardTokenCharge cardTokenCharge = new CardTokenCharge() { CardToken = Order.CardToken, Currency = Order.Currency, Value = (Order.Total * 100).ToString(), Email = Order.Cust.Email }; HttpResponse <Charge> response = await CheckoutClient.ChargeServiceAsync.ChargeWithCardTokenAsync(cardTokenCharge); Charge charge = response.Model; return(charge.ResponseCode); } catch (Exception e) { Debug.WriteLine($"There was an exception: {e}"); return("exception"); } }
/// <summary> /// Creates a charge with card token. /// </summary> public HttpResponse <Charge> ChargeWithCardToken(CardTokenCharge requestModel) { var request = new RestRequest(Endpoints.CardTokenCharge, Method.POST); request.RequestFormat = DataFormat.Json; request.AddBody(requestModel); return(Execute <Charge>(request)); }
public void QueryTransactions_ShouldAllowFilteringWithOperator_ForEmailWithTransactionHistory(Operator?op) { TokenCard cardCreateModel = TestHelper.GetTokenCardModel(); HttpResponse <CardTokenCreate> cardTokenResponse = CheckoutClient.TokenService.GetCardToken(cardCreateModel); CardTokenCharge cardTokenChargeModel = TestHelper.GetCardTokenChargeCreateModel(cardTokenResponse.Model.Id, TestHelper.RandomData.Email); HttpResponse <Charge> chargeResponse = CheckoutClient.ChargeService.ChargeWithCardToken(cardTokenChargeModel); QueryTransactions_ShouldAllowFilteringWithOperator(chargeResponse.Model.Email, op); }
/// <summary> /// Creates a charge with card token. /// </summary> public HttpResponse <Charge> ChargeWithCardToken(CardTokenCharge requestModel) { return(new ApiHttpClient().PostRequest <Charge>(ApiUrls.CardTokenCharge, AppSettings.SecretKey, requestModel)); }
public ActionResult PostCreditCard([Bind(Prefix = "cko-card-token")] string cardToken) { // Create payload // https://docs.checkout.com/reference/merchant-api-reference/charges/charge-with-card-token var shippingAddress = CreateCheckoutAddress(); var billingAddress = CreateCheckoutAddress(); var product = CreateCheckoutProduct(); var orderId = Guid.NewGuid(); var amount = ((product.Price * product.Quantity) + product.ShippingCost); // Find out the card type var cardType = GetCardType(cardToken); if (cardType == "Credit") { amount *= 1.025m; // 2% credit card surcharge } var payload = new CardTokenCharge() { //AutoCapture = "Y", // transfer funds automatically //AutoCapTime = 0, // transfer funds immediately after authorisation AutoCapture = "N", // manually capture ChargeMode = 1, // non-3D Email = "*****@*****.**", Description = "Order", Value = (amount * 100).ToString("0"), Currency = "GBP", TrackId = orderId.ToString(), TransactionIndicator = "1", // regular CustomerIp = Request.ServerVariables["REMOTE_ADDR"] ?? Request.ServerVariables["HTTP_X_FORWARDED_FOR"], CardToken = cardToken, ShippingDetails = shippingAddress, // billing address?? Products = new List <Product>() { product } }; var client = CreateAPIClient(); // Authorise var response = client.ChargeWithCardToken(payload); if (response.HasError) { throw new Exception(response.Error.Message); } if (response.HttpStatusCode != HttpStatusCode.OK) { throw new Exception(string.Format("Failed with status code: {0}", response.HttpStatusCode)); } var charge = response.Model; Session["CreditCard.Charge"] = charge; // TODO: Check payment was authorised before capturing. // Capture var captureResponse = client.CaptureCharge(charge.Id, new ChargeCapture() { // I don't see the point in sending this info?? Value = charge.Value, Description = charge.Description, Products = charge.Products }); if (captureResponse.HasError) { throw new Exception(captureResponse.Error.Message); } if (captureResponse.HttpStatusCode != HttpStatusCode.OK) { throw new Exception(string.Format("Failed with status code: {0}", captureResponse.HttpStatusCode)); } var capture = captureResponse.Model; Session["CreditCard.Capture"] = capture; return(View("Confirmation")); }
public Task <HttpResponse <Charge> > ChargeWithCardTokenAsync(CardTokenCharge requestModel) { return(_apiHttpClient.PostRequest <Charge>(_configuration.ApiUrls.CardTokenCharge, _configuration.SecretKey, requestModel)); }
public HttpResponse <Charge> ChargeWithCardToken(CardTokenCharge requestModel) { return(_chargeServiceAsync.ChargeWithCardTokenAsync(requestModel).Result); }