/** * AUTO_GENERATED */ public PreapprovalResponse Preapproval(PreapprovalRequest preapprovalRequest, string apiUserName) { string response = Call("Preapproval", preapprovalRequest.ToNVPString(""), apiUserName); NVPUtil util = new NVPUtil(); return(PreapprovalResponse.CreateInstance(util.ParseNVPString(response), "", -1)); }
public ActionResult PreapprovalStatus(string preapproval_id) { int iid = 0; bool valid = Int32.TryParse(preapproval_id, out iid); if (!valid) { ViewBag.Msg = "error"; ViewBag.amount = 0; return(View("Status")); } ViewBag.checkout_id = iid; var req = new PreapprovalRequest { accessToken = WePayConfig.accessToken, preapproval_id = iid }; var resp = new WePaySDK.Preapproval().GetStatus(req); if (resp.Error != null) { ViewBag.Error = resp.Error.error + " - " + resp.Error.error_description; return(View("Status")); } ViewBag.state = resp.state; ViewBag.amount = string.Format("{0:c}", resp.amount); ViewBag.Msg = "Preapproval Complete"; return(View("Status")); }
/** * */ public PreapprovalResponse Preapproval(PreapprovalRequest PreapprovalRequest, string apiUsername) { string resp = call("Preapproval", PreapprovalRequest.toNVPString(""), apiUsername); NVPUtil util = new NVPUtil(); return(new PreapprovalResponse(util.parseNVPString(resp), "")); }
/// <summary> /// /// </summary> ///<param name="preapprovalRequest"></param> ///<param name="credential">An explicit ICredential object that you want to authenticate this call against</param> public PreapprovalResponse Preapproval(PreapprovalRequest preapprovalRequest, ICredential credential) { IAPICallPreHandler apiCallPreHandler = new PlatformAPICallPreHandler(this.config, preapprovalRequest.ToNVPString(string.Empty), ServiceName, "Preapproval", credential); ((PlatformAPICallPreHandler)apiCallPreHandler).SDKName = SDKName; ((PlatformAPICallPreHandler)apiCallPreHandler).SDKVersion = SDKVersion; ((PlatformAPICallPreHandler)apiCallPreHandler).PortName = "AdaptivePayments"; NVPUtil util = new NVPUtil(); return(PreapprovalResponse.CreateInstance(util.ParseNVPString(Call(apiCallPreHandler)), string.Empty, -1)); }
// # Preapproval API Operation public PreapprovalResponse PreapprovalAPIOperation(decimal rate, string userId, DateTime subscriptionDate) { // Create the PreapprovalResponse object PreapprovalResponse responsePreapproval = new PreapprovalResponse(); try { // # PreapprovalRequest // The code for the language in which errors are returned RequestEnvelope envelopeRequest = new RequestEnvelope(); envelopeRequest.errorLanguage = "en_US"; PreapprovalRequest requestPreapproval = new PreapprovalRequest(); requestPreapproval.requestEnvelope = envelopeRequest; requestPreapproval.returnUrl = System.Configuration.ConfigurationManager.AppSettings["RETURN_URL"] + "/DoctorInformation/PayPalSubscription/?pstatus=success&userId=" + userId; requestPreapproval.cancelUrl = System.Configuration.ConfigurationManager.AppSettings["CANCEL_URL"] + "/DoctorInformation/PayPalSubscription/?pstatus=cancel&userid=" + userId; requestPreapproval.currencyCode = "USD"; requestPreapproval.startingDate = subscriptionDate.ToString("yyyy-MM-dd"); requestPreapproval.endingDate = subscriptionDate.AddYears(1).ToString("yyyy-MM-dd"); requestPreapproval.feesPayer = "EACHRECEIVER"; requestPreapproval.maxAmountPerPayment = rate; requestPreapproval.maxNumberOfPaymentsPerPeriod = 1; requestPreapproval.maxTotalAmountOfAllPayments = (12 * rate); requestPreapproval.maxNumberOfPayments = 12; //requestPreapproval.dateOfMonth = 27; requestPreapproval.pinType = "NOT_REQUIRED"; //if(!string.IsNullOrEmpty(paypalId)) // requestPreapproval.senderEmail = paypalId; requestPreapproval.paymentPeriod = "DAILY"; // IPN URL // // * PayPal Instant Payment Notification is a call back system that is initiated when a transaction is completed // * The transaction related IPN variables will be received on the call back URL specified in the request // * The IPN variables have to be sent back to the PayPal system for validation, upon validation PayPal will send a response string "VERIFIED" or "INVALID" // * PayPal would continuously resend IPN if a wrong IPN is sent requestPreapproval.ipnNotificationUrl = System.Configuration.ConfigurationManager.AppSettings["IPN_URL"] + "/DoctorInformation/PayPalIPN/"; // Create the service wrapper object to make the API call AdaptivePaymentsService service = new AdaptivePaymentsService(); // # API call // Invoke the Preapproval method in service wrapper object responsePreapproval = service.Preapproval(requestPreapproval); if (responsePreapproval != null) { //// Response envelope acknowledgement //string acknowledgement = "Preapproval API Operation - "; //acknowledgement += responsePreapproval.responseEnvelope.ack.ToString(); //logger.Info(acknowledgement + "\n"); //Console.WriteLine(acknowledgement + "\n"); // # Success values if (responsePreapproval.responseEnvelope.ack.ToString().Trim().ToUpper().Equals("SUCCESS")) { //logger.Info("Preapproval Key : " + responsePreapproval.preapprovalKey + "\n"); //Console.WriteLine("Preapproval Key : " + responsePreapproval.preapprovalKey + "\n"); // Once you get success response, user has to redirect to PayPal // to preapprove the payment. Construct redirectURL as follows, // `redirectURL=https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_ap-preapproval&preapprovalkey=" // + responsePreapproval.preapprovalKey;` string url = String.Format("https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_ap-preapproval&preapprovalkey={0}", responsePreapproval.preapprovalKey); if (HttpContext.Current != null) { HttpContext.Current.Response.Redirect(url); } } // # Error Values else { List <ErrorData> errorMessages = responsePreapproval.error; foreach (ErrorData error in errorMessages) { //logger.Debug("API Error Message : " + error.message); //Console.WriteLine("API Error Message : " + error.message + "\n"); } } } } // # Exception log catch (System.Exception ex) { // Log the exception message } return(responsePreapproval); }
/// <summary> /// Handle Preapproval API /// </summary> /// <param name="context"></param> private void Preapproval(HttpContext context) { NameValueCollection parameters = context.Request.Params; PreapprovalRequest req = new PreapprovalRequest(new RequestEnvelope("en_US"), parameters["cancelUrl"], parameters["currencyCode"], parameters["returnUrl"], parameters["startingDate"]); // set optional parameters if(parameters["dateOfMonth"] != "") { req.dateOfMonth = Int32.Parse(parameters["dateOfMonth"]); } if(parameters["dayOfWeek"] != "" && parameters["dayOfWeek"] != "") { req.dayOfWeek = (PayPal.AdaptivePayments.Model.DayOfWeek) Enum.Parse(typeof(PayPal.AdaptivePayments.Model.DayOfWeek), parameters["dayOfWeek"]); } if(parameters["dateOfMonth"] != "") { req.dateOfMonth = Int32.Parse(parameters["dateOfMonth"]); } if(parameters["endingDate"] != "") { req.endingDate = parameters["endingDate"]; } if(parameters["maxAmountPerPayment"] != "") { req.maxAmountPerPayment = Decimal.Parse(parameters["maxAmountPerPayment"]); } if(parameters["maxNumberOfPayments"] != "" ) { req.maxNumberOfPayments = Int32.Parse(parameters["maxNumberOfPayments"]); } if(parameters["maxNumberOfPaymentsPerPeriod"] != "") { req.maxNumberOfPaymentsPerPeriod = Int32.Parse(parameters["maxNumberOfPaymentsPerPeriod"]); } if(parameters["maxTotalAmountOfAllPayments"] != "") { req.maxTotalAmountOfAllPayments = Decimal.Parse(parameters["maxTotalAmountOfAllPayments"]); } if(parameters["paymentPeriod"] != "" && parameters["paymentPeriod"] != "") { req.paymentPeriod = parameters["paymentPeriod"]; } if(parameters["memo"] != "") { req.memo = parameters["memo"]; } if(parameters["ipnNotificationUrl"] != "") { req.ipnNotificationUrl = parameters["ipnNotificationUrl"]; } if(parameters["senderEmail"] != "") { req.senderEmail = parameters["senderEmail"]; } if(parameters["pinType"] != "" && parameters["pinType"] != "") { req.pinType = parameters["pinType"]; } if(parameters["feesPayer"] != "") { req.feesPayer = parameters["feesPayer"]; } if (parameters["displayMaxTotalAmount"] != "") { req.displayMaxTotalAmount = Boolean.Parse(parameters["displayMaxTotalAmount"]); } // All set. Fire the request AdaptivePaymentsService service = new AdaptivePaymentsService(); PreapprovalResponse resp = null; try { resp = service.Preapproval(req); } catch (System.Exception e) { context.Response.Write(e.Message); return; } // Display response values. Dictionary<string, string> keyResponseParams = new Dictionary<string, string>(); string redirectUrl = null; if (!(resp.responseEnvelope.ack == AckCode.FAILURE) && !(resp.responseEnvelope.ack == AckCode.FAILUREWITHWARNING)) { keyResponseParams.Add("Preapproval key", resp.preapprovalKey); } displayResponse(context, "Preapproval", keyResponseParams, service.getLastRequest(), service.getLastResponse(), resp.error, redirectUrl); }
// # Preapproval API Operation // Use the Preapproval API operation to set up an agreement between yourself and a sender for making payments on the sender’s behalf. You set up a preapprovals for a specific maximum amount over a specific period of time and, optionally, by any of the following constraints: the number of payments, a maximum per-payment amount, a specific day of the week or the month, and whether or not a PIN is required for each payment request. public PreapprovalResponse PreapprovalAPIOperation() { // Create the PreapprovalResponse object PreapprovalResponse responsePreapproval = new PreapprovalResponse(); try { // # PreapprovalRequest // The code for the language in which errors are returned RequestEnvelope envelopeRequest = new RequestEnvelope(); envelopeRequest.errorLanguage = "en_US"; // PreapprovalRequest takes mandatory params: // // * `RequestEnvelope` - Information common to each API operation, such // as the language in which an error message is returned. // * `Cancel URL` - URL to redirect the sender's browser to after // canceling the preapproval // * `Currency Code` - The code for the currency in which the payment is // made; you can specify only one currency, regardless of the number of // receivers // * `Return URL` - URL to redirect the sender's browser to after the // sender has logged into PayPal and confirmed the preapproval // * `Starting Date` - First date for which the preapproval is valid. It // cannot be before today's date or after the ending date. PreapprovalRequest requestPreapproval = new PreapprovalRequest(envelopeRequest, "http://localhost/cancel", "USD", "http://localhost/return", "2013-12-18"); // IPN URL // // * PayPal Instant Payment Notification is a call back system that is initiated when a transaction is completed // * The transaction related IPN variables will be received on the call back URL specified in the request // * The IPN variables have to be sent back to the PayPal system for validation, upon validation PayPal will send a response string "VERIFIED" or "INVALID" // * PayPal would continuously resend IPN if a wrong IPN is sent requestPreapproval.ipnNotificationUrl = "http://IPNhost"; // Create the service wrapper object to make the API call AdaptivePaymentsService service = new AdaptivePaymentsService(); // # API call // Invoke the Preapproval method in service wrapper object responsePreapproval = service.Preapproval(requestPreapproval); if (responsePreapproval != null) { // Response envelope acknowledgement string acknowledgement = "Preapproval API Operation - "; acknowledgement += responsePreapproval.responseEnvelope.ack.ToString(); logger.Info(acknowledgement + "\n"); Console.WriteLine(acknowledgement + "\n"); // # Success values if (responsePreapproval.responseEnvelope.ack.ToString().Trim().ToUpper().Equals("SUCCESS")) { logger.Info("Preapproval Key : " + responsePreapproval.preapprovalKey + "\n"); Console.WriteLine("Preapproval Key : " + responsePreapproval.preapprovalKey + "\n"); // Once you get success response, user has to redirect to PayPal // to preapprove the payment. Construct redirectURL as follows, // `redirectURL=https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_ap-preapproval&preapprovalkey=" // + responsePreapproval.preapprovalKey;` } // # Error Values else { List <ErrorData> errorMessages = responsePreapproval.error; foreach (ErrorData error in errorMessages) { logger.Debug("API Error Message : " + error.message); Console.WriteLine("API Error Message : " + error.message + "\n"); } } } } // # Exception log catch (System.Exception ex) { // Log the exception message logger.Debug("Error Message : " + ex.Message); Console.WriteLine("Error Message : " + ex.Message); } return(responsePreapproval); }
/// <summary> /// /// </summary> ///<param name="preapprovalRequest"></param> public PreapprovalResponse Preapproval(PreapprovalRequest preapprovalRequest) { return(Preapproval(preapprovalRequest, (string)null)); }
public PreapprovalResponse Preapproval(PreapprovalRequest PreapprovalRequest) { return(Preapproval(PreapprovalRequest, null)); }
public string SetPreapproval(fbuser fbuser, bool Live_Trial, int Tx_Key, decimal amount) { string strReturn = ""; PreapprovalRequest preapprovalRequest = null; BaseAPIProfile profile2 = new BaseAPIProfile(); profile2.APIProfileType = ProfileType.ThreeToken; if (Live_Trial)//true = Live , false = trial { profile2.Environment = ConfigurationManager.AppSettings.Get("Live_Environment").ToString(); profile2.ApplicationID = ConfigurationManager.AppSettings.Get("AppID_Live").ToString(); profile2.APIUsername = ConfigurationManager.AppSettings.Get("APIUsername_Live").ToString(); profile2.APIPassword = ConfigurationManager.AppSettings.Get("APIPassword_Live").ToString(); profile2.APISignature = ConfigurationManager.AppSettings.Get("APISignature_Live").ToString(); } else { profile2.Environment = ConfigurationManager.AppSettings.Get("Trial_Environment").ToString(); profile2.ApplicationID = ConfigurationManager.AppSettings.Get("AppID").ToString(); profile2.APIUsername = ConfigurationManager.AppSettings.Get("APIUsername").ToString(); profile2.APIPassword = ConfigurationManager.AppSettings.Get("APIPassword").ToString(); profile2.APISignature = ConfigurationManager.AppSettings.Get("APISignature").ToString(); } profile2.RequestDataformat = "SOAP11"; profile2.ResponseDataformat = "SOAP11"; profile2.IsTrustAllCertificates = Convert.ToBoolean(ConfigurationManager.AppSettings["TrustAll"]); try { decimal amountfee1 = (amount * Convert.ToDecimal(0.029)) + Convert.ToDecimal(0.3); decimal amountblueikon = (amount * Convert.ToDecimal(0.1)); decimal amountfee2 = (amountblueikon * Convert.ToDecimal(0.029)) + Convert.ToDecimal(0.3); amount = amount + amountblueikon + amountfee1 + amountfee2; amount = decimal.Round(amount, 2); string url = ConfigurationManager.AppSettings.Get("App_URL").ToString() ; string returnURL = "http://www.blueikons.com/Order_Confirmation.aspx?Tx_key=" + Tx_Key.ToString(); string cancelURL = url; preapprovalRequest = new PreapprovalRequest(); preapprovalRequest.cancelUrl = cancelURL; preapprovalRequest.returnUrl = returnURL; //preapprovalRequest.senderEmail = senderEmail.Value; preapprovalRequest.requestEnvelope = new RequestEnvelope(); preapprovalRequest.requestEnvelope.errorLanguage = "en-US"; preapprovalRequest.maxNumberOfPayments = 2; preapprovalRequest.maxTotalAmountOfAllPayments = amount; preapprovalRequest.maxTotalAmountOfAllPaymentsSpecified = true; preapprovalRequest.currencyCode = "USD"; preapprovalRequest.startingDate = DateTime.Today; preapprovalRequest.endingDate = DateTime.Today.AddMonths(1); preapprovalRequest.endingDateSpecified = true; preapprovalRequest.clientDetails = new ClientDetailsType(); //preapprovalRequest.clientDetails = ClientInfoUtil.getMyAppDetails(); preapprovalRequest.memo = "BlueIkons"; preapprovalRequest.maxNumberOfPayments = 2; preapprovalRequest.displayMaxTotalAmount = true; preapprovalRequest.displayMaxTotalAmountSpecified = true; preapprovalRequest.feesPayer = "SENDER"; AdapativePayments ap = new AdapativePayments(); ap.APIProfile = profile2; PreapprovalResponse PResponse = ap.preapproval(preapprovalRequest); if (ap.isSuccess.ToUpper() == "FAILURE") { //HttpContext.Current.Session[Constants.SessionConstants.FAULT] = ap.LastError; //HttpContext.Current.Response.Redirect("APIError.aspx", false); } else { // Session[Constants.SessionConstants.PREAPPROVALKEY] = PResponse.preapprovalKey; //this.Response.Redirect(ConfigurationManager.AppSettings["PAYPAL_REDIRECT_URL"] + "_ap-preapproval&preapprovalkey=" + PResponse.preapprovalKey, false); BlueIkons_DB.SPs.UpdateTransactionPakey(Tx_Key, PResponse.preapprovalKey).Execute(); if (Live_Trial)//true = Live , false = trial { //HttpContext.Current.Response.Redirect("https://paypal.com/webapps/adaptivepayment/flow/pay?paykey=" + PResponse.preapprovalKey, false); } else{ //HttpContext.Current.Response.Redirect("https://www.sandbox.paypal.com/webscr?cmd=" + "_ap-payment&paykey=" + PResponse.preapprovalKey, false); } strReturn = PResponse.preapprovalKey; } } catch (FATALException FATALEx) { // Session[Constants.SessionConstants.FATALEXCEPTION] = FATALEx; // this.Response.Redirect(Constants.ASPXPages.APIERROR + "?" + Constants.QueryStringConstants.TYPE + "=FATAL", false); } catch (Exception ex) { //FATALException FATALEx = new FATALException("Error occurred in PreApproval Page.", ex); //Session[Constants.SessionConstants.FATALEXCEPTION] = FATALEx; //this.Response.Redirect("APIError.aspx?type=FATAL", false); } return strReturn; }