public HttpResponse <PaymentToken> CreatePaymentToken(PaymentTokenCreate requestModel) { var request = new RestRequest(Endpoints.PaymentToken, Method.POST); request.RequestFormat = DataFormat.Json; request.AddBody(requestModel); return(Execute <PaymentToken>(request)); }
protected void but_createPaymentToken_Click(object sender, EventArgs e) { // Create payload var paymentTokenCreateRequest = new PaymentTokenCreate() { Value = tb_value.Text, Currency = tb_currency.Text, ChargeMode = 1, Udf1 = "new token", AutoCapture = "N" }; try { // Create APIClient instance with your secret key APIClient ckoAPIClient = new APIClient(); // Submit your request and receive an apiResponse HttpResponse <Checkout.ApiServices.Tokens.ResponseModels.PaymentToken> apiResponse = ckoAPIClient.TokenService.CreatePaymentToken(paymentTokenCreateRequest); if (!apiResponse.HasError) { // Access the response object retrieved from the api var token = apiResponse.Model; tb_createRsp.Text = String.Format("Token ID:\n {0} \n\nJSON Response: \n {1}", token.Id, apiResponse.FullJsonResponse); } else { // Api has returned an error object. You can access the details in the error property of the apiResponse. // apiResponse.error tb_createRsp.Text = string.Format("Event ID:\n{0} \n\nMessage:\n{1} \n\nError Code:\n{2} \n\nErrors:\n{3}", apiResponse.Error.EventId, apiResponse.Error.Message, apiResponse.Error.ErrorCode, apiResponse.Error.Errors); } } catch (Exception exc) { //... Handle exception } }
public string sPayTok() { string payTok = string.Empty; // Create payload var paymentTokenCreateRequest = new PaymentTokenCreate() { Value = "100", Currency = "USD", ChargeMode = 2, // A valid charge mode: 1 for No 3D, 2 for 3D, 3 Local Payment. Default is 1 if not provided. Udf1 = "new token", TrackId = "tracker 123456", AutoCapture = "N" }; // Create APIClient instance with your secret key APIClient ckoAPIClient = new APIClient(); try { // Submit your request and receive an apiResponse HttpResponse <Checkout.ApiServices.Tokens.ResponseModels.PaymentToken> apiResponse = ckoAPIClient.TokenService.CreatePaymentToken(paymentTokenCreateRequest); if (!apiResponse.HasError) { // Access the response object retrieved from the api var response = apiResponse.Model; payTok = response.Id; } else { } } catch (Exception exc) { //... Handle exception } return(payTok); }
public string sPayTok() { string payTok = string.Empty; // Create payload var paymentTokenCreateRequest = new PaymentTokenCreate() { Value = "100", Currency = "USD", ChargeMode = 1, Udf1 = "new token", AutoCapture = "N", CustomerIp = "1.2.3.4" //doesnt get passed on to the charge object. set this in the charge request instead. }; // Create APIClient instance with your secret key APIClient ckoAPIClient = new APIClient(); try { // Submit your request and receive an apiResponse HttpResponse <Checkout.ApiServices.Tokens.ResponseModels.PaymentToken> apiResponse = ckoAPIClient.TokenService.CreatePaymentToken(paymentTokenCreateRequest); if (!apiResponse.HasError) { // Access the response object retrieved from the api var response = apiResponse.Model; payTok = response.Id; } else { } } catch (Exception exc) { //... Handle exception } return(payTok); }
public string sPayTok() { string payTok = string.Empty; // Create payload var paymentTokenCreateRequest = new PaymentTokenCreate() { Value = "100", // this value gets sent for processing even if the aspx front end displays a different value due to error or other reason. Currency = "USD", ChargeMode = 1, //A valid charge mode: 1 for No 3D, 2 for 3D, 3 Local Payment. Default is 1 if not provided. Udf1 = "new token", AutoCapture = "N", CustomerIp = "118.200.158.51" }; // Create APIClient instance with your secret key APIClient ckoAPIClient = new APIClient(); try { // Submit your request and receive an apiResponse HttpResponse <Checkout.ApiServices.Tokens.ResponseModels.PaymentToken> apiResponse = ckoAPIClient.TokenService.CreatePaymentToken(paymentTokenCreateRequest); if (!apiResponse.HasError) { // Access the response object retrieved from the api var response = apiResponse.Model; payTok = response.Id; } else { } } catch (Exception exc) { } return(payTok); }
private ActionResult PayPalCheckout() { // https://docs.checkout.com/getting-started/merchant-api/alternative-payments/paypal/authorise-paypal-charge // Step 1: Create a Payment Token var shippingAddress = CreateCheckoutAddress(); var billingAddress = CreateCheckoutAddress(); var product = CreateCheckoutProduct(); var orderId = Guid.NewGuid(); var email = "*****@*****.**"; var amount = ((product.Price * product.Quantity) + product.ShippingCost); var paymentTokenCreate = new PaymentTokenCreate() { Value = (amount * 100).ToString("0"), Currency = "GBP", AutoCapture = "N", // In addition, autoCapture must be set to n to capture authorised charges manually as can be seen in our Instant Settlement guide. ChargeMode = 3, // chargeMode must be set to 3 for all Alternative Payments. Email = email, //CustomerIp = Request.ServerVariables["REMOTE_ADDR"] ?? Request.ServerVariables["HTTP_X_FORWARDED_FOR"], TrackId = orderId.ToString(), // The trackId parameter is required when creating a payment token to be used with PayPal and should be unique for each request. Description = "Order", //ShippingDetails = shippingAddress, // billing address?? //Products = new List<Product>() { product } }; var client = CreateAPIClient(); var paymentTokenResponse = client.CreatePaymentToken(paymentTokenCreate); if (paymentTokenResponse.HasError) { throw new Exception(paymentTokenResponse.Error.Message); } if (paymentTokenResponse.HttpStatusCode != HttpStatusCode.OK) { throw new Exception(string.Format("Failed with status code: {0}", paymentTokenResponse.HttpStatusCode)); } var paymentToken = paymentTokenResponse.Model; Session["PayPal.PaymentToken"] = paymentToken; // Step 2: Create an Alternative Payment Charge var localPaymentChargeRequest = new LocalPaymentCharge() { Email = email, LocalPayment = new LocalPaymentCreate() { LppId = "lpp_19", // PayPal - https://docs.checkout.com/reference/checkout-js-reference/alternative-payments UserData = new Dictionary <string, string>() }, PaymentToken = paymentToken.Id }; var alternativePaymentChargeResponse = client.ChargeWithLocalPayment(localPaymentChargeRequest); if (alternativePaymentChargeResponse.HasError) { throw new Exception(alternativePaymentChargeResponse.Error.Message); } if (alternativePaymentChargeResponse.HttpStatusCode != HttpStatusCode.OK) { throw new Exception(string.Format("Failed with status code: {0}", alternativePaymentChargeResponse.HttpStatusCode)); } var charge = alternativePaymentChargeResponse.Model; // Step 3: Handle Alternative Payment Response if (charge.ResponseCode != "10000") { throw new Exception("Unexpected response code creating charge: " + charge.ResponseCode); } if (charge.LocalPayment == null || string.IsNullOrWhiteSpace(charge.LocalPayment.PaymentUrl)) { throw new Exception("No payment url for alternative charge: " + charge.ResponseCode); } Session["PayPal.LocalPaymentCharge"] = charge; return(Redirect(charge.LocalPayment.PaymentUrl)); }
public Task <HttpResponse <PaymentToken> > CreatePaymentTokenAsync(PaymentTokenCreate requestModel) { return(_apiHttpClient.PostRequest <PaymentToken>(_configuration.ApiUrls.PaymentToken, _configuration.SecretKey, requestModel)); }
public HttpResponse <PaymentToken> CreatePaymentToken(PaymentTokenCreate requestModel) { return(new ApiHttpClient().PostRequest <PaymentToken>(ApiUrls.PaymentToken, AppSettings.SecretKey, requestModel)); }
public HttpResponse <PaymentToken> CreatePaymentToken(PaymentTokenCreate requestModel) { return(_tokenServiceAsync.CreatePaymentTokenAsync(requestModel).Result); }