public PaymentGatewayResponse() { this.ErrorCode = PaymentGatewayErrorCode.GenericError; this.Success = false; this.Message = "Generic Error"; this.ResolutionAction = PaymentGatewayResolutionAction.NoAction; }
/// <summary> /// endpoint: /API/Laser.Orchard.PaymentGateway/PaymentGatewayAPI/GetVirtualPosUrl /// Get the Url of the virtual pos, based on the parameters passed in the call. /// Example response: /// { /// "ErrorCode": 0, /// "ResolutionAction": 0, /// "Success": true, /// "Message": "The Data object contains the array of valid filter parameters. These are case-insensitive."", /// "Data": { /// "redirectUrl": "https://testecomm.sella.it/pagam/pagam.aspx?a=GESPAY63353&b=JEkIJQMBqbRabcJwzbGRHI1q8*dZOkTVfBzFjl0ciCaOrUZpYxTgDgDAG_SIC_Uy1uUBChnOEqs0fmXc2K9WTgsGDi*qlTQa*A_Nq*F2ylc" /// } /// } /// </summary> /// <param name="posName">Mandatory: Name of the payment gateway whose POS we are trying to reach.</param> /// <param name="amount">Mandatory: Amount to be payed.</param> /// <param name="currency">Mandatory: Currency of payment.</param> /// <param name="itemId">Optional: Id of Content Item associated with payment.</param> /// <param name="reason">Optional: Description of reason for payment.</param> /// <param name="redirectUrl">Optional: Url to which we want to redirect the browser from the Action handling the end of /// the transaction.</param> /// <param name="schema">Optional: Schema for the redirect from the Action handling the end of the transaction.</param> /// <param name="filters">Optional: Comma-separated list of parameters for the json filter of the results. The valid strings are given by a call to GetAPIFilterTerms. /// The response received at the end of the transaction will contain the requested parameters in addition to the default ones.</param> /// <returns>A response whose Data field contains a redirectUrl string telling where the application should redirect the user for payment, /// or an error with aditional information.</returns> public PaymentGatewayResponse GetVirtualPosUrl( string posName, decimal amount, string currency, int?itemId = 0, string reason = "", string redirectUrl = "", string schema = "", string filters = "") { bool success = false; string msg = ""; dynamic data = new System.Dynamic.ExpandoObject(); PaymentGatewayErrorCode error = PaymentGatewayErrorCode.NoError; PaymentGatewayResolutionAction action = PaymentGatewayResolutionAction.NoAction; //get pos from posName var pos = _posServices.Where(ps => ps.GetPosName() == posName).SingleOrDefault(); if (pos == null) { //ERROR: no pos with that name success = false; error = PaymentGatewayErrorCode.PosNotFound; action = PaymentGatewayResolutionAction.UpdatePosNames; data.posNames = AllPosNames(); msg = T("Could not find a POS called \"{0}\": you may find a list of available POS names in this response's data object.", posName).Text; } else { //check whether currency is valid var vc = ValidCurrencies(pos); if (string.IsNullOrWhiteSpace(currency) || !vc.Contains(currency)) { //currency is required success = false; error = PaymentGatewayErrorCode.InvalidCurrency; action = PaymentGatewayResolutionAction.VerifyInformation; data.validCurrencies = vc; msg = T("A valid currency is required. You may find a list of valid currencies in this response's data object.").Text; } else { //create PaymentRecord (using startPayment) PaymentRecord record = null; try { //create a string for the apifilters, keeping only the valid ones, and removing duplicates filters = string.Join(",", filters.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries) .Where(s => PaymentRecord.IsValidAPIFilter(s)) .Distinct(StringComparer.InvariantCultureIgnoreCase) .ToList()); record = pos.StartPayment(new PaymentRecord() { Reason = reason, Amount = amount, Currency = currency, ContentItemId = itemId.Value, CustomRedirectUrl = redirectUrl, CustomRedirectSchema = schema, APIFilters = filters }); } catch (Exception ex) { success = false; error = PaymentGatewayErrorCode.ImpossibleToCreateRecord; action = PaymentGatewayResolutionAction.VerifyInformation; msg = ex.Message; } int paymentId = record.Id; //get the redirect url for the pos try { data.redirectUrl = pos.GetPosUrl(paymentId); success = true; } catch (Exception ex) { //some payment services may not return a redirect url (e.g. Braintree) //handle this case with an error success = false; msg = ex.Message; error = PaymentGatewayErrorCode.CallNotValid; action = PaymentGatewayResolutionAction.DoSomethingElse; } } } return(new PaymentGatewayResponse() { Success = success, Message = msg, Data = data, ErrorCode = error, ResolutionAction = action }); }