Ejemplo n.º 1
0
        public static CreditCard GetCreditCardDetailsFromVault(string creditCardId)
        {
            try
            {
                //Getting the API Context to authenticate the call
                APIContext apiContext = PayPalConfig.GetAPIContext();

                //Getting the Credit Card Details from paypal
                //By sending the Card ID saved at our end
                CreditCard card = CreditCard.Get(apiContext, creditCardId); // "CARD-00N04036H5458422MKRIAWHY"
                return(card);
            }
            catch (PayPal.PayPalException ex)
            {
                //Logger.LogError("Error: " + ex.Message);
            }

            return(null);
        }
Ejemplo n.º 2
0
        public static bool DeleteCreditCardFromVault(string creditCardId)
        {
            try
            {
                // Getting the API Context for authentication the call to paypal server
                APIContext apiContext = PayPalConfig.GetAPIContext();

                //get the credit card from the vault to delete
                CreditCard card = CreditCard.Get(apiContext, creditCardId); // "CARD-00N04036H5458422MKRIAWHY"

                // Delete the credit card
                card.Delete(apiContext);

                return(true);
            }
            catch (PayPal.PayPalException ex)
            {
                //Logger.LogError("Error: " + ex.Message);
                return(false);
            }
        }
Ejemplo n.º 3
0
        // https://www.codeproject.com/Tips/886187/PayPal-REST-API-Recurring-Payment-via-Stored-Credi
        // https://code.tutsplus.com/articles/paypal-integration-part-2-paypal-rest-api--cms-22917

        public static string StoreCreditCardInPaypal(PaypalViewModel._Payer._FundingInstrument._CreditCard cc)
        {
            //Creating the CreditCard Object and assigning values
            var creditCard = new CreditCard
            {
                expire_month = cc.ExpireMonth,
                expire_year  = cc.ExpireYear,
                number       = cc.CcNumber,
                type         = cc.CcType,
                cvv2         = cc.Cvv2
            };

            try
            {
                //Getting the API Context to authenticate the call to Paypal Server
                APIContext apiContext = PayPalConfig.GetAPIContext();
                // Storing the Credit Card Info in the PayPal Vault Server
                CreditCard createdCreditCard = creditCard.Create(apiContext);

                //Saving the User's Credit Card ID returned by the PayPal
                //You can use this ID for future payments via User's Credit Card
                //SaveCardID(User.Identity.Name, createdCreditCard.id);

                return(createdCreditCard.id);
            }
            catch (PayPal.PayPalException ex)
            {
                //Logger.LogError("Error: " + ex.Message);
                return(ex.Message);
            }
            catch (Exception ex)
            {
                //Logger.LogError("Error: " + ex.Message);
                return(ex.Message);
            }
        }