jeudi 14 avril 2016

how to Integrate Paypal module using Angularjs asp.net mvc?

i am create small shopping cart demo and integrate the paypal module in angularjs with asp.net mvc..but i am not get the perfect result..i have tried the below code in my small shopping cart demo..then i have get the error your shopping cart is empty.. this is my controller method..

   public ActionResult ValidCommand(AddToCart Cart)
    {
        var userid = Convert.ToInt32(CookieHelper.GetCookieValue(CookieKeys.UserID));
        bool useSandBox = Convert.ToBoolean(ConfigurationManager.AppSettings["IsSendBox"]);
        var paypal = new payPalMode(useSandBox);

        List<AddToCart> c_list = new List<AddToCart>();
        var carts = from c in db.AddToCarts
                    join p in db.tblProducts
                    on c.ProductId equals p.ProductId
                    where (c.UserId == userid)
                    select new
                    {
                        cid = c.CartId,
                        pprice = p.Price,
                        pid = p.ProductId,
                        pname = p.ProductName,
                        pdesc = p.Descripation,
                        img = p.Image,
                        qun = c.Quantity
                    };
        foreach (var item in carts)
        {
            AddToCart ctbl = new AddToCart();
            ctbl.CartId = item.cid;
            ctbl.Quantity = item.qun;
            ctbl.ProductId = item.pid;
            ctbl.productName = item.pname;
            ctbl.Descripation = item.pdesc;
            ctbl.price = item.pprice;
            ctbl.Image = item.img;
            c_list.Add(ctbl);
        }
        paypal.CartList = c_list;
        return View("ValidCommand", paypal);
    }

this is my paypal.cs class

public class payPalMode
{
    public string cmd { get; set; }
    public string business { get; set; }
    public string no_shipping { get; set; }
    public string @return { get; set; }
    public string cancel_return { get; set; }
    public string notify_url { get; set; }
    public string curreny_code { get; set; }
    public string actionUrl { get; set; }
    public string Cart { get; set; }
    public string upload { get; set; }

    public List<AddToCart> CartList = new List<AddToCart>();

    public payPalMode(bool useSandBox)
    {
        this.cmd = "_cart";

        this.business = ConfigurationManager.AppSettings["business"];
        this.cancel_return = ConfigurationManager.AppSettings["cancel_return"];
        this.@return = ConfigurationManager.AppSettings["return"];
        useSandBox = true;
        if (useSandBox)
        {
            this.actionUrl = ConfigurationManager.AppSettings["test_url"];
        }
        else
        {
            this.actionUrl = ConfigurationManager.AppSettings["Prod_url"];
        }
        this.notify_url = ConfigurationManager.AppSettings["notify_url"];
        this.curreny_code = ConfigurationManager.AppSettings["currency_code"];
        this.upload = ConfigurationManager.AppSettings["upload"];
        this.no_shipping = "1";
    }
}

this is my angularjs funaction..

$scope.checkout = function () {
    debugger;
    var getdata = AngularService.checkout();
    debugger;
    getdata.then(function (data) {
        debugger;
        $rootScope.item = data;

    })
};

this is my view..

<body>
<div ng-app="MyApp" ng-controller="AddToCart">
<form id="hiddenform" action="@Model.actionUrl">
    @Html.HiddenFor(model => model.cmd)
    @Html.HiddenFor(model => model.business)
    @Html.HiddenFor(model => model.no_shipping)
    @Html.HiddenFor(model => model.@return)
    @Html.HiddenFor(model => model.cancel_return)
    @Html.HiddenFor(model => model.notify_url)
    @Html.HiddenFor(model => model.curreny_code)
    @Html.HiddenFor(model => model.upload)
    @{
        var count = 1;

        foreach (var item in Model.CartList)
        {
            string name = "item_name" + count;
            string amount = "amount" + count;

            <input type="hidden" name="@name" value="@item.productName" />
            <input type="hidden" name="@amount" value="@item.price" />

            count++;
        }
    }
</form>
<h2>Connect To PayPal</h2>
</div>

this above code i have tried and get the error your shopping cart is empty.so please any one idea about it so please tell me...

Aucun commentaire:

Enregistrer un commentaire