/// <summary>
        /// Creates a charge with an alternative/local payment.
        /// </summary>
        /// <param name="requestModel">The request model.</param>
        /// <returns></returns>
        public HttpResponse <Charge> ChargeWithLocalPayment(LocalPaymentCharge requestModel)
        {
            var request = new RestRequest(Endpoints.LocalPaymentCharge, Method.POST);

            request.RequestFormat = DataFormat.Json;
            request.AddBody(requestModel);
            return(Execute <Charge>(request));
        }
Example #2
0
        public static LocalPaymentCharge GetLocalPaymentChargeModel(string paymentToken, string lppId = "lpp_9", Dictionary <string, string> userData = null)
        {
            var localPayment = new LocalPaymentCharge
            {
                Email        = RandomData.Email,
                LocalPayment = new LocalPaymentCreate
                {
                    LppId    = lppId,
                    UserData = userData ?? new Dictionary <string, string> {
                        { "issuerId", "INGBNL2A" }
                    }
                },
                PaymentToken = paymentToken
            };

            return(localPayment);
        }
 /// <summary>
 /// Creates a charge with an alternative/local payment.
 /// </summary>
 /// <param name="requestModel">The request model.</param>
 /// <returns></returns>
 public HttpResponse <Charge> ChargeWithLocalPayment(LocalPaymentCharge requestModel)
 {
     return(new ApiHttpClient().PostRequest <Charge>(ApiUrls.LocalPaymentCharge, AppSettings.SecretKey, requestModel));
 }
Example #4
0
        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));
        }
Example #5
0
 public Task <HttpResponse <Charge> > ChargeWithLocalPaymentAsync(LocalPaymentCharge requestModel)
 {
     return(_apiHttpClient.PostRequest <Charge>(_configuration.ApiUrls.LocalPaymentCharge, _configuration.SecretKey, requestModel));
 }
Example #6
0
 public HttpResponse <Charge> ChargeWithLocalPayment(LocalPaymentCharge requestModel)
 {
     return(_chargeServiceAsync.ChargeWithLocalPaymentAsync(requestModel).Result);
 }