Example #1
0
        public static string ConfirmSale(Quote quote)
        {
            Dictionary <string, string> payPalConfig = new Dictionary <string, string>();

            payPalConfig.Add("mode", mode.ToString());

            string     AccessToken = GetPayPalAccessToken();
            APIContext AC          = new APIContext(AccessToken);

            AC.Config = payPalConfig;

            Payee pe = new Payee();

            pe.merchant_id = "Q4A2XY37JY7VW";

            RedirectUrls ru = new RedirectUrls();

            ru.return_url = "https://www.chimaeraconspiracy.com/checkout/approved?Quote=" + quote.QuoteKey;
            ru.cancel_url = "https://www.chimaeraconspiracy.com/checkout/cancelled";

            Payer pyr = new Payer();

            pyr.payment_method = "paypal";

            decimal subtotal = QuoteService.CalculateSubtotal(quote);

            if (quote.Discount != null)
            {
                subtotal -= DiscountService.CalculateDiscount(quote.Discount, subtotal);
            }

            List <Transaction> transactions = new List <Transaction>();
            Transaction        t            = new Transaction();

            t.amount                  = new Amount();
            t.amount.currency         = "USD";
            t.amount.details          = new Details();
            t.amount.details.subtotal = subtotal.ToString("0.00");
            t.amount.details.tax      = "0.00";
            t.amount.details.shipping = quote.ShippingCharge.Value.ToString("0.00");
            t.amount.total            = Math.Round(subtotal + quote.ShippingCharge.Value, 2, MidpointRounding.AwayFromZero).ToString("0.00");
            t.description             = "Chimaera Conspiracy Shop Purchase";

            Payment p = new Payment();

            p.intent        = "sale";
            p.payer         = pyr;
            p.redirect_urls = ru;
            p.transactions  = new List <Transaction>()
            {
                t
            };

            Payment pResp = p.Create(AC);

            if (pResp.state.Equals("created", StringComparison.OrdinalIgnoreCase))
            {
                return(pResp.links.Where(x => x.rel.Equals("approval_url", StringComparison.OrdinalIgnoreCase)).Select(y => y.href).FirstOrDefault());
            }

            throw new Exception("Paypal: approval_url missing");
        }