/// <summary>
		/// Post process payment (used by payment gateways that require redirecting to a third-party URL)
		/// </summary>
		/// <param name="postProcessPaymentRequest">Payment info required for an order processing</param>
		public override void PostProcessPayment(PostProcessPaymentRequest postProcessPaymentRequest)
		{
			if (postProcessPaymentRequest.Order.PaymentStatus == PaymentStatus.Paid)
				return;
			var settings = _services.Settings.LoadSetting<PayUMeaStandardPaymentSettings>(postProcessPaymentRequest.Order.StoreId);
			if (_payUApiComms == null)
			{

				_payUApiComms = new RunPayUComms(settings.Username, settings.Password, settings.ApiUrl, settings.SafeKey, "ONE_ZERO");
			}
			string cancelReturnUrl = _services.WebHelper.GetStoreLocation(false) + "Plugins/PaymentPayUPayUMeaStandard/CancelOrder";
			var orderid = postProcessPaymentRequest.Order.GetOrderNumber();
			string returnUrl = string.Format("{0}Plugins/PaymentPayUMeaStandard/PDTHandler?orderId={1}", _services.WebHelper.GetStoreLocation(false), orderid);
			var setTransactionResult = _payUApiComms.SetTransaction(new SetTransactionRequest
			{
				AmountInCents = Math.Truncate(postProcessPaymentRequest.Order.OrderTotal * 100).ToString(CultureInfo.InvariantCulture),
				CancelUrl = cancelReturnUrl,
				CustomerEmail = postProcessPaymentRequest.Order.BillingAddress.Email,
				CustomerLastname = postProcessPaymentRequest.Order.BillingAddress.LastName,
				CustomerMobile = postProcessPaymentRequest.Order.BillingAddress.PhoneNumber,
				CustomerName = postProcessPaymentRequest.Order.BillingAddress.FirstName,
				CustomerUsername = postProcessPaymentRequest.Order.Customer.Username,
				LineItems = postProcessPaymentRequest.Order.OrderItems.Select(x => new LineItem
				{
					Amount = Math.Truncate(x.PriceInclTax * 100).ToString(CultureInfo.InvariantCulture),
					Description = x.Product.Name,
					ProductCode = x.Product.Sku,
					Quantity = x.Quantity.ToString()
				}).ToList(),
				OrderNumber =  postProcessPaymentRequest.Order.OrderGuid.ToString(),
				PaymentTypes = null,
				ReturnUrl = returnUrl,
				Stage = false
			});
			if (!setTransactionResult.IsTransactionSet)
				throw new Exception(string.Format("Failed to Preprocess transaction with PayU ### {0} ###>> {1}:{2}:{3}", setTransactionResult.ErrorMessage, postProcessPaymentRequest.Order.BillingAddress.Email, postProcessPaymentRequest.Order.OrderNumber, postProcessPaymentRequest.Order.OrderGuid));
			_httpContext.Response.Redirect(string.Format("{0}?PayUReference={1}", settings.RedirectUrl, setTransactionResult.PayUReference));
		}
Esempio n. 2
0
 public void TestSetup()
 {
     _comms = new RunPayUComms("100032", "PypWWegU", "https://staging.payu.co.za/service/PayUAPI?wsdl", "{CE62CE80-0EFD-4035-87C1-8824C5C46E7F}", "ONE_ZERO");
 }
		public ActionResult IPNHandler()
		{
			Debug.WriteLine("PayUMea Standard IPN: {0}".FormatWith(Request.ContentLength));

			var provider = _paymentService.LoadPaymentMethodBySystemName("Payments.PayUMeaStandard", true);
			var processor = provider != null ? provider.Value as PayUMeaStandardProvider : null;
			if (processor == null)
				throw new SmartException(_localizationService.GetResource("Plugins.Payments.PayUMeaStandard.NoModuleLoading"));


			var ueasyPaymentSettings = _services.Settings.LoadSetting<PayUMeaStandardPaymentSettings>();
			var runPayUcomms = new RunPayUComms(ueasyPaymentSettings.Username, ueasyPaymentSettings.Password, ueasyPaymentSettings.ApiUrl, ueasyPaymentSettings.SafeKey, "ONE_ZERO");
			var transactionRequest1 = new GetTransactionRequest
			{
				PayUReference = Request.QueryString["payUReference"]
			};
			var transaction = runPayUcomms.GetTransaction(transactionRequest1);
			var orderByNumber = _orderService.GetOrderByNumber(Request.QueryString["orderId"]);
			switch (transaction.TransactionState)
			{
				case "RESERVE":
					orderByNumber.AuthorizationTransactionId = Request.QueryString["payUReference"];
					_orderService.UpdateOrder(orderByNumber);
					_orderProcessingService.MarkAsAuthorized(orderByNumber);
					break;
				case "RESERVE_CANCEL":
					orderByNumber.AuthorizationTransactionId = Request.QueryString["payUReference"];
					_orderService.UpdateOrder(orderByNumber);
					_orderProcessingService.CancelOrder(orderByNumber, true);
					break;
				case "PAYMENT":
					orderByNumber.AuthorizationTransactionId = Request.QueryString["payUReference"];
					_orderService.UpdateOrder(orderByNumber);
					_orderProcessingService.MarkOrderAsPaid(orderByNumber);
					break;
				case "FINALIZE":
					orderByNumber.AuthorizationTransactionId = Request.QueryString["payUReference"];
					_orderService.UpdateOrder(orderByNumber);
					_orderProcessingService.MarkOrderAsPaid(orderByNumber);
					break;
			}
			return Content("");
		}