Esempio n. 1
0
        public bool DoDirectPaymentSuccess(BuyGiftCardModel model)
        {
            bool success = false;

            com.paypal.sdk.services.NVPCallerServices caller = PayPalAPI.PayPalAPIInitialize();
            NVPCodec encoder = new NVPCodec();

            encoder["METHOD"]         = "DoDirectPayment";
            encoder["PAYMENTACTION"]  = "Sale";
            encoder["IPADDRESS"]      = Helper.CurrentUserIP;
            encoder["AMT"]            = Helper.FormatPriceToPayPalStringFormat(model.Amount);
            encoder["CREDITCARDTYPE"] = CreditCardTypeRepository.GetCreditCardTypeById(int.Parse(model.CardType)).Title;
            encoder["ACCT"]           = model.CardNumber;
            encoder["EXPDATE"]        = int.Parse(model.ExpirationMonth).ToString() + int.Parse(model.ExpirationYear).ToString();
            encoder["CVV2"]           = int.Parse(model.SecurityCode).ToString();
            encoder["FIRSTNAME"]      = model.BillFirstName;
            encoder["LASTNAME"]       = model.BillLastName;
            encoder["CURRENCYCODE"]   = "USD";

            string pStrrequestforNvp = encoder.Encode();
            string pStresponsenvp    = caller.Call(pStrrequestforNvp);

            NVPCodec decoder = new NVPCodec();

            decoder.Decode(pStresponsenvp);

            string strAck = decoder["ACK"];

            if (strAck != null && (strAck == "Success" || strAck == "SuccessWithWarning"))
            {
                Session["result"] = decoder;
                // string pStrResQue = "API=" + "DoDirect Payment ";
                success = true;
            }
            else
            {
                Session["errorresult"] = decoder;
            }
            return(success);
        }
    public static bool PerformPayment(string CreditCardType, string CreditCardNumber, string CVV2, string ExpMonth, string ExpYear,
                                      string FirstName, string LastName, string Address1, string Address2, string City, string State, string Zip,
                                      string Country, string CountryCode, decimal Amount, out string Errors)


    {
        // LMG - maybe this should be set somewhere else??  4/28
        SetProfile.SessionProfile = SetProfile.CreateAPIProfile(Constants.API_USERNAME, Constants.API_PASSWORD, Constants.API_SIGNATURE, "", "");

        com.paypal.sdk.services.NVPCallerServices caller = PayPalAPI.PayPalAPIInitialize();
        NVPCodec encoder = new NVPCodec();

        encoder["METHOD"] = "DoDirectPayment";
        // encoder["PAYMENTACTION"] = this.Request.QueryString[Constants.PAYMENT_TYPE_PARAM];
        encoder["PAYMENTACTION"] = "Sale";
        encoder["AMT"]           = Amount.ToString();
        //encoder["AMT"] = ".01";
        encoder["CREDITCARDTYPE"] = CreditCardType;
        encoder["ACCT"]           = CreditCardNumber;
        encoder["EXPDATE"]        = ExpMonth + ExpYear;
        encoder["CVV2"]           = CVV2;
        encoder["FIRSTNAME"]      = FirstName;
        encoder["LASTNAME"]       = LastName;
        encoder["STREET"]         = Address1;
        encoder["CITY"]           = City;
        encoder["STATE"]          = State;
        encoder["ZIP"]            = Zip;
        encoder["COUNTRYCODE"]    = CountryCode;
        encoder["CURRENCYCODE"]   = "USD";

        string pStrrequestforNvp = encoder.Encode();
        // Actually Process the Card and put response etc. into pStresponsenvp
        string pStresponsenvp = caller.Call(pStrrequestforNvp);

        NVPCodec decoder = new NVPCodec();

        //
        decoder.Decode(pStresponsenvp);
        //
        string strAck = decoder["ACK"];

        Errors = "";
        if (strAck != null && (strAck == "Success" || strAck == "SuccessWithWarning"))
        {
            // Card passes, YES  (should we do a result=yes?  (note: result = bool)
            string pStrResQue = "TRANSACTIONID=" + decoder["TRANSACTIONID"] + "&" +
                                "AMT=" + decoder["AMT"] + "&" +
                                "AVSCODE=" + decoder["AVSCODE"] + "&" +
                                "CVV2MATCH=" + decoder["CVV2MATCH"];
            return(true);
//                Response.Redirect("paymentreceipt.aspx?" + pStrResQue);
        }
        else
        {
            // Card does not pass, or Paypal has an error.
            string pStrError = "ErrorCode=" + decoder["L_ERRORCODE0"] + "&" +
                               "Desc=" + decoder["L_SHORTMESSAGE0"] + "&" +
                               "Desc2=" + decoder["L_LONGMESSAGE0"];
            Errors = pStrError;
            return(false);
            //              Response.Redirect("PayPalAPIError.aspx?" + pStrError);
        }
    }