Example #1
0
        async public void offer_pack()
        {
            try
            {
                if (offer_username == "" || offer_username == null)
                {
                    await new MessageDialog("Entrez un pseudo").ShowAsync();
                    return;
                }

                var user_id = await Http_get.get_user_by_username(offer_username);

                if (user_id == null)
                {
                    await new MessageDialog("Entrez un pseudo existant.").ShowAsync();
                    return;
                }



                PayPal.Checkout.BuyNow purchase = new PayPal.Checkout.BuyNow("*****@*****.**");
                purchase.UseSandbox = true;
                purchase.Currency = "EUR";

                PayPal.Checkout.ItemBuilder itemBuilder = new PayPal.Checkout.ItemBuilder("W8_PP")
                    .ID("W8_PP")
                    .Price(amount.ToString())
                    .Description(pack.title)
                    .Quantity(1);

                purchase.AddItem(itemBuilder.Build());

                purchase.Error += new EventHandler<PayPal.Checkout.Event.ErrorEventArgs>((source, eventArg) =>
                {
                    this.txt_pp = "Une erreur est survenue lors du paiement." + eventArg.Message;
                });
                purchase.Auth += new EventHandler<PayPal.Checkout.Event.AuthEventArgs>((source, eventArg) =>
                {
                    this.txt_pp = "Authentification: " + eventArg.Token;
                });
                purchase.Start += new EventHandler<PayPal.Checkout.Event.StartEventArgs>((source, eventArg) =>
                {
                    this.txt_pp = "Chargement de PayPal...";
                });
                purchase.Complete += new EventHandler<PayPal.Checkout.Event.CompleteEventArgs>((source, eventArg) =>
                {
                    this.txt_pp = "Le paiement à été validé." + eventArg.TransactionID;
                    this.pp_transac_id = eventArg.TransactionID;
                    this.offer_cart_after_pp_validation(user_id.id);
                });
                purchase.Cancel += new EventHandler<PayPal.Checkout.Event.CancelEventArgs>((source, eventArg) =>
                {
                    this.txt_pp = "Le paiement à été annulé par l'utilisateur.";
                });

                // Launch the secure PayPal interface. This is an asynchronous method
                await purchase.Execute();
            }
            catch (Exception Error)
            {
                new MessageDialog("Erreur lors de la connexion avec PayPal").ShowAsync();
            }
        }
Example #2
0
        //async public void buy_pack() OLD
        //{
        //    Exception exception = null;
        //    var request = new Http_post();

        //    try
        //    {
        //        string secureKey = await Security.getSecureKey(Singleton.Instance.Current_user.id.ToString());

        //        // NOT DONE -> FIND WHAT F**K IT UP
        //        string pack_data =
        //            "user_id=" + Singleton.Instance.Current_user.id +
        //            "&secureKey=" + secureKey +
        //            "&pack_id=" + pack.id.ToString() +
        //            "&amount=" + amount.ToString() + 
        //            "&artist=" + artist.ToString() + 
        //            "&association=" + association.ToString() + 
        //            "&website=" + website.ToString();


        //        // HTTP_POST -> URL + DATA
        //        var response = await request.post_request("purchases/buypack", pack_data);

        //        var json = JObject.Parse(response).SelectToken("message");

        //        // NO CONTENT RETURNED WHEN OK
        //        if (json.ToString() == "Created")
        //            await new MessageDialog("Purchase PACK OK").ShowAsync();
        //        else
        //            await new MessageDialog(json.ToString(), "Purchase PACK KO").ShowAsync();
        //    }
        //    catch (Exception e)
        //    {
        //        exception = e;
        //    }

        //    if (exception != null)
        //        await new MessageDialog(exception.Message, "Purchase PACK error").ShowAsync();
        //}

        async public void buy_pack()
        {
            try
            {
                //PayPal.Checkout.BuyNow purchase = new PayPal.Checkout.BuyNow("*****@*****.**");
                //PayPal.Checkout.BuyNow purchase = new PayPal.Checkout.BuyNow("*****@*****.**");
                PayPal.Checkout.BuyNow purchase = new PayPal.Checkout.BuyNow("*****@*****.**");

                purchase.UseSandbox = true;

                purchase.Currency = "EUR";

                // Use the ItemBuilder to create a new example item
                PayPal.Checkout.ItemBuilder itemBuilder = new PayPal.Checkout.ItemBuilder("W8_PP")
                    .ID("W8_PP")
                    .Price(amount.ToString())
                    .Description(pack.title)
                    .Quantity(1);

                // Add the item to the purchase,
                purchase.AddItem(itemBuilder.Build());

                // Attach event handlers so you will be notified of important events
                // The BuyNow interface provides 5 events - Start, Auth, Cancel, Complete and Error
                // See http://paypal.github.io/Windows8SDK/csharp.html#Events for more
                purchase.Error += new EventHandler<PayPal.Checkout.Event.ErrorEventArgs>((source, eventArg) =>
                {
                    this.txt_pp = "Une erreur est survenue lors du paiement." + eventArg.Message;
                });
                purchase.Auth += new EventHandler<PayPal.Checkout.Event.AuthEventArgs>((source, eventArg) =>
                {
                    this.txt_pp = "Authentification: " + eventArg.Token;
                });
                purchase.Start += new EventHandler<PayPal.Checkout.Event.StartEventArgs>((source, eventArg) =>
                {
                    this.txt_pp = "Chargement de PayPal...";
                });
                purchase.Complete += new EventHandler<PayPal.Checkout.Event.CompleteEventArgs>((source, eventArg) =>
                {
                    //buy_cart_after_pp_validation();
                    this.txt_pp = "Le paiement à été validé." + eventArg.TransactionID;
                    this.pp_transac_id = eventArg.TransactionID;
                    this.buy_cart_after_pp_validation();
                });
                purchase.Cancel += new EventHandler<PayPal.Checkout.Event.CancelEventArgs>((source, eventArg) =>
                {
                    this.txt_pp = "Le paiement à été annulé par l'utilisateur.";
                });

                // Launch the secure PayPal interface. This is an asynchronous method
                await purchase.Execute();
            }
            catch (Exception Error)
            {
                new MessageDialog("Erreur lors de la connexion avec PayPal").ShowAsync();
            }
        } //buy_cart_after_pp_validation