public NameValueCollection DoExpressCheckoutPayment(decimal amount, CurrencyCodeType currencyCodeType, string payPalToken, string payPalPayerId, PaymentAction action) { var request = getQueryWithCredentials(); request["METHOD"] = "DoExpressCheckoutPayment"; request["TOKEN"] = payPalToken; request["PAYERID"] = payPalPayerId; request["PAYMENTREQUEST_0_AMT"] = amount.ToString("0.00"); request["PAYMENTREQUEST_0_CURRENCYCODE"] = currencyCodeType.ToString(); request["PAYMENTREQUEST_0_PAYMENTACTION"] = action.ToString(); return request; }
public NameValueCollection DoExpressCheckoutPayment(decimal amount, CurrencyCodeType currencyCodeType, string payPalToken, string payPalPayerId, PaymentAction action) { var request = getQueryWithCredentials(); request["METHOD"] = "DoExpressCheckoutPayment"; request["TOKEN"] = payPalToken; request["PAYERID"] = payPalPayerId; request["PAYMENTREQUEST_0_AMT"] = amount.ToString("0.00"); request["PAYMENTREQUEST_0_CURRENCYCODE"] = currencyCodeType.ToString(); request["PAYMENTREQUEST_0_PAYMENTACTION"] = action.ToString(); return(request); }
protected string DoPayment(Payment payment, NameValueCollection details) { IDictionary <string, string> values = new Dictionary <string, string>(); // Set up call values.Add("USER", payment.PaymentMethod.DynamicProperty <string>().ApiUsername); values.Add("PWD", payment.PaymentMethod.DynamicProperty <string>().ApiPassword); values.Add("SIGNATURE", payment.PaymentMethod.DynamicProperty <string>().ApiSignature); values.Add("METHOD", "DoExpressCheckoutPayment"); values.Add("VERSION", "98.0"); string[] fieldsToCopy = { "TOKEN", "PAYERID", "PAYMENTREQUEST_0_CURRENCYCODE", "PAYMENTREQUEST_0_AMT" }; foreach (string key in details) { if (fieldsToCopy.Contains(key)) { values.Add(key, details[key]); } } PaymentAction pa = EnumExtensions.ParsePaymentActionThrowExceptionOnFailure(payment.PaymentMethod.DynamicProperty <string>().PaymentAction); values.Add("PAYMENTREQUEST_0_PAYMENTACTION", pa.ToString()); LogAuditTrail(payment.PurchaseOrder, "DoExpressCheckoutPayment", values); var post = new HttpPost(GetPostUrl(payment.PaymentMethod), values); string response = post.GetString(); NameValueCollection responseValues = HttpUtility.ParseQueryString(response); LogAuditTrail(payment.PurchaseOrder, "DoExpressCheckoutPaymentResponse", responseValues); if (responseValues["ACK"] != "Success") { throw new Exception(response); } var responseAmount = responseValues["PAYMENTINFO_0_AMT"]; CheckReceivedAmountAgainstExpectedValue(payment.Amount, responseAmount, response); string responseCurrency = responseValues["PAYMENTINFO_0_CURRENCYCODE"]; if (payment.PurchaseOrder.BillingCurrency.ISOCode != responseCurrency) { string message = string.Format("Wrong currency. Expected {0}, but was {1}", payment.PurchaseOrder.BillingCurrency.ISOCode, responseCurrency); throw new Exception(message + " - " + response); } return(responseValues["PAYMENTINFO_0_TRANSACTIONID"]); }
protected virtual IDictionary <string, string> GetParameters(PaymentRequest paymentRequest) { var currency = paymentRequest.Amount.CurrencyIsoCode; // For dynamics, we have to call the extension method as a normal method. ReturnMethod rm = EnumExtensions.ParseReturnMethodThrowExceptionOnFailure(paymentRequest.PaymentMethod .DynamicProperty <string>().ReturnMethod); PaymentAction pa = EnumExtensions.ParsePaymentActionThrowExceptionOnFailure(paymentRequest.PaymentMethod .DynamicProperty <string>().PaymentAction); var dict = new Dictionary <string, string> { { "upload", "1" }, { "cmd", "_cart" }, { "business", paymentRequest.PaymentMethod.DynamicProperty <string>().Business }, { "return", new Uri(AbsoluteUrlService.GetAbsoluteUrl(paymentRequest.PaymentMethod.DynamicProperty <string>() .Return)) .AddOrderGuidParameter( paymentRequest.Payment.PurchaseOrder).ToString() }, { "rm", ((int)rm).ToString() }, // Vendor code to identify Ucommerce { "bn", "Ucommerce_SP" }, { "currency_code", currency }, { "no_shipping", "1" }, { "paymentaction", pa.ToString().ToLower() }, { "cancel_return", AbsoluteUrlService.GetAbsoluteUrl(paymentRequest.PaymentMethod.DynamicProperty <string>() .CancelReturn) }, { "notify_url", CallbackUrl.GetCallbackUrl(paymentRequest.PaymentMethod.DynamicProperty <string>().NotifyUrl, paymentRequest.Payment) }, { "invoice", paymentRequest.Payment.ReferenceId }, { "item_name_1", string.Join(", ", paymentRequest.Payment.PurchaseOrder.OrderLines.Select(x => x.ProductName)) }, { "amount_1", paymentRequest.Payment.Amount.ToInvariantString() }, { "quantity_1", "1" } }; return(dict); }
public virtual IDictionary <string, string> GetParameters(PaymentRequest paymentRequest) { Payment payment = paymentRequest.Payment; OrderAddress billingAddress = payment.PurchaseOrder.GetBillingAddress(); var orderAddress = billingAddress; var shipment = payment.PurchaseOrder.Shipments.FirstOrDefault(); if (shipment != null && shipment.ShipmentAddress != null) { orderAddress = shipment.ShipmentAddress; } string orderCurrency = paymentRequest.Payment.PurchaseOrder.BillingCurrency.ISOCode; string referenceId = payment.ReferenceId; string callbackUrl = _callbackUrl.GetCallbackUrl(paymentRequest.PaymentMethod.DynamicProperty <string>().NotifyUrl, payment); string cancelUrl = _absoluteUrlService.GetAbsoluteUrl(paymentRequest.PaymentMethod.DynamicProperty <string>().CancelReturn); IDictionary <string, string> values = new Dictionary <string, string>(); // Set up call values.Add("USER", paymentRequest.PaymentMethod.DynamicProperty <string>().ApiUsername); values.Add("PWD", paymentRequest.PaymentMethod.DynamicProperty <string>().ApiPassword); values.Add("SIGNATURE", paymentRequest.PaymentMethod.DynamicProperty <string>().ApiSignature); values.Add("METHOD", "SetExpressCheckout"); values.Add("VERSION", "98.0"); //Add order values values.Add("RETURNURL", callbackUrl); values.Add("CANCELURL", cancelUrl); values.Add("NOSHIPPING", "1"); values.Add("ALLOWNOTE", "0"); var regionCode = GetRegionCode(paymentRequest); values.Add("LOCALECODE", regionCode); values.Add("SOLUTIONTYPE", "Sole"); values.Add("EMAIL", billingAddress.EmailAddress); //Vendor code to identify Ucommerce values.Add("BUTTONSOURCE", "uCommerce_SP"); values.Add("PAYMENTREQUEST_0_SHIPTONAME", Uri.EscapeDataString(string.Format("{0} {1}", orderAddress.FirstName, orderAddress.LastName))); values.Add("PAYMENTREQUEST_0_SHIPTOSTREET", Uri.EscapeDataString(orderAddress.Line1)); values.Add("PAYMENTREQUEST_0_SHIPTOSTREET2", Uri.EscapeDataString(orderAddress.Line2)); values.Add("PAYMENTREQUEST_0_SHIPTOCITY", Uri.EscapeDataString(orderAddress.City)); values.Add("PAYMENTREQUEST_0_SHIPTOSTATE", Uri.EscapeDataString(orderAddress.State)); values.Add("PAYMENTREQUEST_0_SHIPTOZIP", Uri.EscapeDataString(orderAddress.PostalCode)); values.Add("PAYMENTREQUEST_0_SHIPTOCOUNTRYCODE", Uri.EscapeDataString(orderAddress.Country.TwoLetterISORegionName)); values.Add("PAYMENTREQUEST_0_SHIPTOPHONENUM", Uri.EscapeDataString(orderAddress.PhoneNumber)); string fullAmount = NumberWithTwoDecimalDigitsAfterPeriodAndNoThousandsSeperator(payment.Amount); values.Add("PAYMENTREQUEST_0_AMT", fullAmount); values.Add("PAYMENTREQUEST_0_CURRENCYCODE", orderCurrency); PaymentAction pa = EnumExtensions.ParsePaymentActionThrowExceptionOnFailure(payment.PaymentMethod.DynamicProperty <string>().PaymentAction); values.Add("PAYMENTREQUEST_0_PAYMENTACTION", pa.ToString()); values.Add("PAYMENTREQUEST_0_INVNUM", referenceId); return(values); }