void btnFreeCheckout_Click(object sender, EventArgs e) { if (cart.OrderTotal > 0) { WebUtils.SetupRedirect(this, Request.RawUrl); return; } cart.LastUserActivity = DateTime.UtcNow; cart.OrderInfo.CompletedFromIP = SiteUtils.GetIP4Address(); cart.OrderInfo.Completed = DateTime.UtcNow; StoreHelper.EnsureUserForOrder(cart); cart.Save(); Order order = Order.CreateOrder( store, cart, string.Empty, string.Empty, string.Empty, siteSettings.GetCurrency().Code, "NoCharge", OrderStatus.OrderStatusFulfillableGuid ); StoreHelper.ClearCartCookie(cart.StoreGuid); // send confirmation email try { StoreHelper.ConfirmOrder(store, order); Module m = new Module(store.ModuleId); Order.EnsureSalesReportData(m.ModuleGuid, pageId, moduleId); } catch (Exception ex) { log.Error("error sending confirmation email", ex); } // redirect to order details string redirectUrl = SiteRoot + "/WebStore/OrderDetail.aspx?pageid=" + pageId.ToInvariantString() + "&mid=" + moduleId.ToInvariantString() + "&orderid=" + order.OrderGuid.ToString(); WebUtils.SetupRedirect(this, redirectUrl); }
private void btnMakePayment_Click(object sender, System.EventArgs e) { //Page.Validate(); if ( (store != null) && (cart != null) && (IsValidForCheckout()) ) { IPaymentGateway gateway = commerceConfig.GetDirectPaymentGateway(); if (gateway == null) { lblMessage.Text = WebStoreResources.PaymentGatewayNotConfiguredForDirectCardProcessing; btnMakePayment.Enabled = false; return; } //if (gateway is PlugNPayPaymentGateway) //{ gateway.MerchantInvoiceNumber = cart.CartGuid.ToString("N"); string CartItems = ""; int itemnum = 0; foreach (CartOffer coffer in cart.CartOffers) { itemnum++; CartItems += string.Format("&item{1}={0}&cost{1}={2}&description{1}={3}&quantity{1}={4}", coffer.OfferGuid, itemnum, coffer.OfferPrice, coffer.Name, coffer.Quantity); } gateway.MerchantTransactionDescription = CartItems; //not sure if this is the intended purpose or not //} gateway.CardType = ddCardType.SelectedValue; gateway.CardNumber = txtCardNumber.Text; gateway.CardExpiration = ddExpireMonth.SelectedValue + ddExpireYear.SelectedValue; gateway.ChargeTotal = cart.OrderTotal; gateway.CardSecurityCode = txtCardSecurityCode.Text; gateway.CardOwnerFirstName = txtCardOwnerFirstName.Text; gateway.CardOwnerLastName = txtCardOwnerLastName.Text; gateway.CardOwnerCompanyName = cart.OrderInfo.BillingCompany; gateway.CardBillingAddress = cart.OrderInfo.BillingAddress1 + " " + cart.OrderInfo.BillingAddress2; gateway.CardBillingCity = cart.OrderInfo.BillingCity; gateway.CardBillingState = cart.OrderInfo.BillingState; gateway.CardBillingPostalCode = cart.OrderInfo.BillingPostalCode; gateway.CardBillingCountry = cart.OrderInfo.BillingCountry; gateway.CardBillingCountryCode = cart.OrderInfo.BillingCountry; gateway.CardBillingPhone = cart.OrderInfo.CustomerTelephoneDay; gateway.CustomerIPAddress = SiteUtils.GetIP4Address(); gateway.CurrencyCulture = currencyCulture; // this is where the actual request is made, it can timeout here bool executed = false; try { executed = gateway.ExecuteTransaction(); } catch (WebException ex) { if (commerceConfig.PaymentGatewayUseTestMode) { lblMessage.Text = ex.Message; } else { lblMessage.Text = WebStoreResources.PaymentGatewayCouldNotConnectMessage; } return; } string serializedCart = string.Empty; gateway.LogTransaction( siteSettings.SiteGuid, store.ModuleGuid, store.Guid, cart.CartGuid, cart.UserGuid, string.Empty, "WebStoreCheckout", serializedCart); //if (gateway is PayPalDirectPaymentGateway) //{ // // this is capturing of the serialized cart is not needed for other providers and I'm not sure its even needed for PayPal Direct // // it was needed for other paypal solutions. I just don't want to remove it until I'm sure // cart.SerializeCartOffers(); // serializedCart = SerializationHelper.SerializeToString(cart); // gateway.LogTransaction( // siteSettings.SiteGuid, // store.ModuleGuid, // store.Guid, // cart.CartGuid, // cart.UserGuid, // "WebStorePayPalDirect", // "DirectPayment", // serializedCart); //} //else //{ // gateway.LogTransaction( // siteSettings.SiteGuid, // store.ModuleGuid, // store.Guid, // cart.CartGuid, // cart.UserGuid, // string.Empty, // "WebStoreCheckout", // serializedCart); //} if (executed) { switch (gateway.Response) { case PaymentGatewayResponse.Approved: cart.LastUserActivity = DateTime.UtcNow; cart.OrderInfo.CompletedFromIP = SiteUtils.GetIP4Address(); cart.OrderInfo.Completed = DateTime.UtcNow; StoreHelper.EnsureUserForOrder(cart); cart.Save(); //Order order = Order.CreateOrder(store, cart, gateway, store.DefaultCurrency, "CreditCard"); Order order = Order.CreateOrder(store, cart, gateway, siteSettings.GetCurrency().Code, "CreditCard"); StoreHelper.ClearCartCookie(cart.StoreGuid); // send confirmation email try { // this also happens in StoreHelper.ConfirmOrder //Module m = new Module(store.ModuleId); //Order.EnsureSalesReportData(m.ModuleGuid, pageId, moduleId); StoreHelper.ConfirmOrder(store, order); PayPalLog.DeleteByCart(order.OrderGuid); GoogleCheckoutLog.DeleteByCart(order.OrderGuid); } catch (Exception ex) { log.Error("error sending confirmation email", ex); } // redirect to order details string redirectUrl = SiteRoot + "/WebStore/OrderDetail.aspx?pageid=" + pageId.ToInvariantString() + "&mid=" + moduleId.ToInvariantString() + "&orderid=" + order.OrderGuid.ToString(); //TODO: if we charged a card here we can safely delete any paypal log or googlecheckout logs // need methods to delete those by carguid if (WebStoreConfiguration.LogCardTransactionStatus) { log.Info("accepted transaction " + gateway.ChargeTotal.ToString("c") + " " + gateway.ResponseCode + " " + gateway.ResponseReason); } WebUtils.SetupRedirect(this, redirectUrl); return; case PaymentGatewayResponse.Declined: lblMessage.Text = WebStoreResources.TransactionDeclinedMessage; if ((WebStoreConfiguration.LogCardTransactionStatus) || (WebStoreConfiguration.LogCardFailedTransactionStatus)) { log.Info("declined transaction " + gateway.ChargeTotal.ToString("c") + " " + gateway.ResponseCode + " " + gateway.ResponseReason); } break; case PaymentGatewayResponse.Error: if (gateway.UseTestMode) { if (gateway.LastExecutionException != null) { lblMessage.Text = gateway.LastExecutionException.ToString(); } else { // TODO: should not show user real messages? Mask CCNumber and login credentials in the gateways RawResponse property ... those shouldn't be logged either lblMessage.Text = gateway.RawResponse; } } else { lblMessage.Text = WebStoreResources.TransactionErrorMessage; if ((WebStoreConfiguration.LogCardTransactionStatus) || (WebStoreConfiguration.LogCardFailedTransactionStatus)) { if (gateway.LastExecutionException != null) { log.Info("transaction error " + gateway.LastExecutionException.ToString()); } } } break; case PaymentGatewayResponse.NoRequestInitiated: lblMessage.Text = WebStoreResources.TransactionNotInitiatedMessage; break; } } else { lblMessage.Text = WebStoreResources.TransactionNotInitiatedMessage; if (gateway.LastExecutionException != null) { if (commerceConfig.PaymentGatewayUseTestMode) { lblMessage.Text = gateway.LastExecutionException.ToString(); } } } } btnMakePayment.Text = WebStoreResources.PaymentButton; }
private void btnMakePayment_Click(object sender, EventArgs e) { if (store != null && cart != null && IsValidForCheckout()) { IPaymentGateway gateway = commerceConfig.GetDirectPaymentGateway(); if (gateway == null) { lblMessage.Text = WebStoreResources.PaymentGatewayNotConfiguredForDirectCardProcessing; btnMakePayment.Enabled = false; return; } gateway.MerchantInvoiceNumber = cart.CartGuid.ToString("N"); var cartItems = new List <string>(); foreach (var cartOffer in cart.CartOffers) { cartItems.Add($"({cartOffer.Quantity}x) {cartOffer.Name} {cartOffer.OfferPrice.ToString("c", currencyCulture)} (GUID: {cartOffer.OfferGuid:N})"); } gateway.MerchantTransactionDescription = string.Join("\n", cartItems); gateway.CardType = ddCardType.SelectedValue; gateway.CardNumber = txtCardNumber.Text; gateway.CardExpiration = ddExpireMonth.SelectedValue + ddExpireYear.SelectedValue; gateway.ChargeTotal = cart.OrderTotal; gateway.CardSecurityCode = txtCardSecurityCode.Text; gateway.CardOwnerFirstName = txtCardOwnerFirstName.Text; gateway.CardOwnerLastName = txtCardOwnerLastName.Text; gateway.CardOwnerCompanyName = cart.OrderInfo.BillingCompany; gateway.CardBillingAddress = cart.OrderInfo.BillingAddress1 + " " + cart.OrderInfo.BillingAddress2; gateway.CardBillingCity = cart.OrderInfo.BillingCity; gateway.CardBillingState = cart.OrderInfo.BillingState; gateway.CardBillingPostalCode = cart.OrderInfo.BillingPostalCode; gateway.CardBillingCountry = cart.OrderInfo.BillingCountry; gateway.CardBillingCountryCode = cart.OrderInfo.BillingCountry; gateway.CardBillingPhone = cart.OrderInfo.CustomerTelephoneDay; gateway.CustomerIPAddress = SiteUtils.GetIP4Address(); gateway.CurrencyCulture = currencyCulture; // this is where the actual request is made, it can timeout here bool executed; try { executed = gateway.ExecuteTransaction(); } catch (WebException ex) { if (commerceConfig.PaymentGatewayUseTestMode) { lblMessage.Text = ex.Message; } else { lblMessage.Text = WebStoreResources.PaymentGatewayCouldNotConnectMessage; } return; } var serializedCart = string.Empty; gateway.LogTransaction( siteSettings.SiteGuid, store.ModuleGuid, store.Guid, cart.CartGuid, cart.UserGuid, string.Empty, "WebStoreCheckout", serializedCart ); if (executed) { switch (gateway.Response) { case PaymentGatewayResponse.Approved: cart.LastUserActivity = DateTime.UtcNow; cart.OrderInfo.CompletedFromIP = SiteUtils.GetIP4Address(); cart.OrderInfo.Completed = DateTime.UtcNow; StoreHelper.EnsureUserForOrder(cart); cart.Save(); Order order = Order.CreateOrder(store, cart, gateway, siteSettings.GetCurrency().Code, "CreditCard"); StoreHelper.ClearCartCookie(cart.StoreGuid); // send confirmation email try { // this also happens in StoreHelper.ConfirmOrder StoreHelper.ConfirmOrder(store, order); PayPalLog.DeleteByCart(order.OrderGuid); GoogleCheckoutLog.DeleteByCart(order.OrderGuid); } catch (Exception ex) { log.Error("error sending confirmation email", ex); } // redirect to order details string redirectUrl = SiteRoot + "/WebStore/OrderDetail.aspx?pageid=" + pageId.ToInvariantString() + "&mid=" + moduleId.ToInvariantString() + "&orderid=" + order.OrderGuid.ToString(); //TODO: if we charged a card here we can safely delete any paypal log or googlecheckout logs // need methods to delete those by carguid if (WebStoreConfiguration.LogCardTransactionStatus) { log.Info("accepted transaction " + gateway.ChargeTotal.ToString("c") + " " + gateway.ResponseCode + " " + gateway.ResponseReason); } WebUtils.SetupRedirect(this, redirectUrl); return; case PaymentGatewayResponse.Declined: lblMessage.Text = WebStoreResources.TransactionDeclinedMessage; if (WebStoreConfiguration.LogCardTransactionStatus || WebStoreConfiguration.LogCardFailedTransactionStatus) { log.Info("declined transaction " + gateway.ChargeTotal.ToString("c") + " " + gateway.ResponseCode + " " + gateway.ResponseReason); } break; case PaymentGatewayResponse.Error: if (gateway.UseTestMode) { if (gateway.LastExecutionException != null) { lblMessage.Text = gateway.LastExecutionException.ToString(); } else { // TODO: should not show user real messages? Mask CCNumber and login credentials in the gateways RawResponse property ... those shouldn't be logged either lblMessage.Text = gateway.RawResponse; } } else { lblMessage.Text = WebStoreResources.TransactionErrorMessage; if (WebStoreConfiguration.LogCardTransactionStatus || WebStoreConfiguration.LogCardFailedTransactionStatus) { if (gateway.LastExecutionException != null) { log.Info("transaction error " + gateway.LastExecutionException.ToString()); } } } break; case PaymentGatewayResponse.NoRequestInitiated: lblMessage.Text = WebStoreResources.TransactionNotInitiatedMessage; break; } } else { lblMessage.Text = WebStoreResources.TransactionNotInitiatedMessage + (!string.IsNullOrEmpty(gateway.ResponseReason) ? "<br>" + gateway.ResponseReason : string.Empty); if (gateway.LastExecutionException != null) { if (commerceConfig.PaymentGatewayUseTestMode) { lblMessage.Text = gateway.LastExecutionException.ToString(); } } } } btnMakePayment.Text = WebStoreResources.PaymentButton; }
void btnMakePayment_Click(object sender, EventArgs e) { PayPalExpressGateway gateway = new PayPalExpressGateway( commerceConfig.PayPalAPIUsername, commerceConfig.PayPalAPIPassword, commerceConfig.PayPalAPISignature, commerceConfig.PayPalStandardEmailAddress); gateway.UseTestMode = commerceConfig.PaymentGatewayUseTestMode; gateway.PayPalToken = checkoutDetailsLog.Token; gateway.PayPalPayerId = checkoutDetailsLog.PayerId; gateway.MerchantCartId = cart.CartGuid.ToString(); gateway.ChargeTotal = cart.OrderTotal; gateway.ReturnUrl = SiteRoot + "/Services/PayPalReturnHandler.ashx"; gateway.CancelUrl = SiteUtils.GetCurrentPageUrl(); gateway.CurrencyCode = siteSettings.GetCurrency().Code; // **** here's where the payment is requested ****** bool executed = gateway.CallDoExpressCheckoutPayment(); PayPalLog payPalLog = new PayPalLog(); payPalLog.RequestType = "DoExpressCheckoutPayment"; payPalLog.ProviderName = WebStorePayPalReturnHandler.ProviderName; payPalLog.SerializedObject = checkoutDetailsLog.SerializedObject; payPalLog.ReturnUrl = checkoutDetailsLog.ReturnUrl; payPalLog.RawResponse = gateway.RawResponse; payPalLog.TransactionId = gateway.TransactionId; payPalLog.PaymentType = gateway.PayPalPaymentType; payPalLog.PaymentStatus = gateway.PayPalPaymentStatus; payPalLog.PendingReason = gateway.PayPalPendingReason; payPalLog.ReasonCode = gateway.ReasonCode; payPalLog.PayPalAmt = gateway.ChargeTotal; payPalLog.FeeAmt = gateway.PayPalFeeAmount; payPalLog.SettleAmt = gateway.PayPalSettlementAmount; payPalLog.TaxAmt = gateway.PayPalTaxTotal; payPalLog.Token = gateway.PayPalToken; payPalLog.PayerId = gateway.PayPalPayerId; payPalLog.RequestType = "DoExpressCheckoutPayment"; payPalLog.SiteGuid = store.SiteGuid; payPalLog.StoreGuid = store.Guid; payPalLog.CartGuid = cart.CartGuid; payPalLog.UserGuid = cart.UserGuid; payPalLog.CartTotal = cart.OrderTotal; payPalLog.CurrencyCode = gateway.CurrencyCode; if (gateway.PayPalExchangeRate.Length > 0) { payPalLog.ExchangeRate = decimal.Parse(gateway.PayPalExchangeRate); } payPalLog.Save(); if (!executed) { lblMessage.Text = WebStoreResources.TransactionNotInitiatedMessage; if (gateway.LastExecutionException != null) { log.Error("ExpressCheckout gateway error", gateway.LastExecutionException); if (commerceConfig.PaymentGatewayUseTestMode) { lblMessage.Text = gateway.LastExecutionException.ToString(); } } else { if (commerceConfig.PaymentGatewayUseTestMode) { lblMessage.Text = gateway.RawResponse; } } return; } string redirectUrl = string.Empty; if (gateway.TransactionId.Length == 0) { // TODO: redirect where? redirectUrl = SiteRoot + "/WebStore/PayPalGatewayError.aspx?plog=" + payPalLog.RowGuid.ToString(); Response.Redirect(redirectUrl); } Guid orderStatusGuid; if (payPalLog.PaymentStatus == "Completed") { orderStatusGuid = OrderStatus.OrderStatusFulfillableGuid; } else { orderStatusGuid = OrderStatus.OrderStatusReceivedGuid; } Order order = Order.CreateOrder( store, cart, payPalLog.RawResponse, payPalLog.TransactionId, string.Empty, siteSettings.GetCurrency().Code, "PayPal", orderStatusGuid); StoreHelper.ClearCartCookie(cart.StoreGuid); // send confirmation email // paypal sends an order confirmation so no need // redirect to order details redirectUrl = SiteRoot + "/WebStore/OrderDetail.aspx?pageid=" + PageId.ToString(CultureInfo.InvariantCulture) + "&mid=" + store.ModuleId.ToString(CultureInfo.InvariantCulture) + "&orderid=" + order.OrderGuid.ToString(); Response.Redirect(redirectUrl); }