public void IPNVoid(int OrderNumber) { String result = ""; int ONX = OrderNumber; Order ord = new Order(ONX, Localization.GetDefaultLocale()); Customer c = new Customer(ord.CustomerID); using (SqlConnection conn = DB.dbConn()) { conn.Open(); using (IDataReader rs = DB.GetRS("Select * from Orders with (NOLOCK) where OrderNumber=" + ONX.ToString(), conn)) { if (rs.Read()) { if (DB.RSFieldDateTime(rs, "VoidedOn") == System.DateTime.MinValue) { decimal OrderTotal = 0.0M; int CouponType = 0; string CouponCode = ""; decimal CouponDiscountAmount = 0.0M; OrderTotal = DB.RSFieldDecimal(rs, "OrderTotal"); CouponType = DB.RSFieldInt(rs, "CouponType"); CouponCode = DB.RSField(rs, "CouponCode"); CouponDiscountAmount = DB.RSFieldDecimal(rs, "CouponDiscountAmount"); // make sure inventory was restored. safe to call repeatedly. proc protects against deducting twice DB.ExecuteSQL("aspdnsf_AdjustInventory " + ONX.ToString() + ",1"); Gateway.DecrementMicropayProductsInOrder(ONX); // update transactionstate DB.ExecuteSQL("update Orders set VoidTXCommand='Instant Payment Notification', VoidTXResult=" + DB.SQuote(AppLogic.ro_OK) + ", TransactionState=" + DB.SQuote(AppLogic.ro_TXStateVoided) + ", VoidedOn=getdate(), IsNew=0 where ordernumber=" + ONX.ToString()); //Invalidate GiftCards ordered on this order GiftCards GCs = new GiftCards(ONX, GiftCardCollectionFilterType.OrderNumber); foreach (GiftCard gc in GCs) { gc.GiftCardTransactions.Add(GiftCardUsageTransaction.CreateTransaction(gc.GiftCardID, GiftCardUsageReasons.FundsRemovedByAdmin, 0, 0, gc.Balance, "")); gc.UpdateCard(null, null, null, null, 1, null, null, null, null, null, null, null, null, null, null); } //Restore Amount to coupon used in paying for the order if ((CouponTypeEnum)CouponType == CouponTypeEnum.GiftCard) { GiftCard gc = new GiftCard(CouponCode); if (gc.GiftCardID != 0) { gc.GiftCardTransactions.Add(GiftCardUsageTransaction.CreateTransaction(gc.GiftCardID, GiftCardUsageReasons.FundsAddedByAdmin, 0, 0, CouponDiscountAmount, "")); } } result = AppLogic.ro_OK; } } } } }
void HandleGiftCardsOnCancelledOrder(int orderNumber, int couponType, string couponCode, decimal couponDiscountAmount) { var giftCards = new GiftCards(orderNumber, GiftCardCollectionFilterType.OrderNumber); foreach (GiftCard card in giftCards) { card .GiftCardTransactions .Add(GiftCardUsageTransaction .CreateTransaction(card.GiftCardID, GiftCardUsageReasons.FundsRemovedByAdmin, 0, 0, card.Balance, string.Empty)); card.UpdateCard(null, null, null, null, 1, null, null, null, null, null, null, null, null, null, null); } //Restore Amount to gift card used in paying for the order if ((CouponTypeEnum)couponType == CouponTypeEnum.GiftCard) { var giftCard = new GiftCard(couponCode); if (giftCard.GiftCardID != 0) { giftCard .GiftCardTransactions .Add(GiftCardUsageTransaction .CreateTransaction(giftCard.GiftCardID, GiftCardUsageReasons.FundsAddedByAdmin, 0, 0, couponDiscountAmount, string.Empty)); } } }
public void IPNRefund(int OrderNumber, String RefundTransID, Decimal RefundAmount) { String result = ""; if (RefundAmount < 0) { RefundAmount = (decimal)(-1.0) * RefundAmount; } int ONX = OrderNumber; Order ord = new Order(ONX, Localization.GetDefaultLocale()); Customer c = new Customer(ord.CustomerID); decimal OrderTotal = 0.0M; int CouponType = 0; string CouponCode = ""; decimal CouponDiscountAmount = 0.0M; String RefundReason = "PayPal IPN Refund"; using (SqlConnection conn = DB.dbConn()) { conn.Open(); using (IDataReader rs = DB.GetRS("Select * from Orders with (NOLOCK) where OrderNumber=" + ONX.ToString(), conn)) { if (rs.Read()) { string PM = AppLogic.CleanPaymentMethod(DB.RSField(rs, "PaymentMethod")); if (DB.RSFieldDateTime(rs, "RefundedOn") == System.DateTime.MinValue) { if (DB.RSFieldDateTime(rs, "CapturedOn") != System.DateTime.MinValue) { if (DB.RSField(rs, "TransactionState") == AppLogic.ro_TXStateCaptured) { OrderTotal = DB.RSFieldDecimal(rs, "OrderTotal"); CouponType = DB.RSFieldInt(rs, "CouponType"); CouponCode = DB.RSField(rs, "CouponCode"); CouponDiscountAmount = DB.RSFieldDecimal(rs, "CouponDiscountAmount"); DB.ExecuteSQL("update orders set RefundTXCommand='Instant Payment Notification', RefundTXResult=" + DB.SQuote(AppLogic.ro_OK) + ", AuthorizationPNREF=AuthorizationPNREF+" + DB.SQuote("|REFUND=" + RefundTransID) + " where OrderNumber=" + ONX.ToString()); result = AppLogic.ro_OK; } } } } } } if (result == AppLogic.ro_OK) { // was this a full refund // we can only properly handle IPN's for refunds of the full order amount if (RefundAmount == System.Decimal.Zero || RefundAmount == OrderTotal) { // make sure inventory was restored. safe to call repeatedly. proc protects against deducting twice DB.ExecuteSQL("aspdnsf_AdjustInventory " + ONX.ToString() + ",1"); Gateway.DecrementMicropayProductsInOrder(ONX); // update transactionstate DB.ExecuteSQL("update Orders set RefundReason=" + DB.SQuote(RefundReason) + ", TransactionState=" + DB.SQuote(AppLogic.ro_TXStateRefunded) + ", RefundedOn=getdate(), IsNew=0 where OrderNumber=" + ONX.ToString()); //Invalidate GiftCards ordered on this order GiftCards GCs = new GiftCards(ONX, GiftCardCollectionFilterType.OrderNumber); foreach (GiftCard gc in GCs) { gc.GiftCardTransactions.Add(GiftCardUsageTransaction.CreateTransaction(gc.GiftCardID, GiftCardUsageReasons.FundsRemovedByAdmin, 0, 0, gc.Balance, "")); gc.UpdateCard(null, null, null, null, 1, null, null, null, null, null, null, null, null, null, null); } //Restore Amount to coupon used in paying for the order if ((CouponTypeEnum)CouponType == CouponTypeEnum.GiftCard) { GiftCard gc = new GiftCard(CouponCode); if (gc.GiftCardID != 0) { gc.GiftCardTransactions.Add(GiftCardUsageTransaction.CreateTransaction(gc.GiftCardID, GiftCardUsageReasons.FundsAddedByAdmin, 0, 0, CouponDiscountAmount, "")); } } } } }