本文整理汇总了C#中Transaction.Save方法的典型用法代码示例。如果您正苦于以下问题:C# Transaction.Save方法的具体用法?C# Transaction.Save怎么用?C# Transaction.Save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Transaction
的用法示例。
在下文中一共展示了Transaction.Save方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Do
public override CommandResult Do(IExecutionContext context)
{
Transaction transaction = new Transaction
{
TransactionName = TransactionName,
TransactionState = TransactionState.Undefined
};
try
{
context.ExecutedPackage.AddTransaction(transaction);
Command.Do(context, transaction);
SetProgress(context, Command, CommandResult.Next);
transaction.TransactionState = TransactionState.Active;
}
catch
{
transaction.Rollback();
}
finally
{
transaction.Save(context);
}
return CommandResult.Next;
}
示例2: Refund
public Transaction Refund(Transaction transaction, Order order)
{
Transaction refundedTransaction = new Transaction();
refundedTransaction.OrderId = transaction.OrderId;
refundedTransaction.TransactionTypeDescriptorId = (int)TransactionType.Refund;
refundedTransaction.PaymentMethod = order.CreditCardType.ToString();
refundedTransaction.GatewayName = "Null Payment Provider";
refundedTransaction.GatewayResponse = "Refunded";
refundedTransaction.GatewayTransactionId = Core.CoreUtility.GenerateRandomString(16);
refundedTransaction.TransactionDate = DateTime.UtcNow;
refundedTransaction.GrossAmount = Convert.ToDecimal(order.Total);
transaction.GatewayErrors = string.Empty;
transaction.AVSCode = "N/A";
transaction.CVV2Code = "N/A";
transaction.Save(SYSTEM);
return refundedTransaction;
}
示例3: DoExpressCheckout
//.........这里部分代码省略.........
#region ShipTo Address
//Load up The ShipTo Address
paymentDetails.ShipToAddress = new PayPalSvc.AddressType();
paymentDetails.ShipToAddress.Name =
order.ShippingAddress.FirstName + " " + order.ShippingAddress.LastName;
paymentDetails.ShipToAddress.Street1 =
order.ShippingAddress.Address1;
paymentDetails.ShipToAddress.Street2 =
order.ShippingAddress.Address2;
paymentDetails.ShipToAddress.CityName =
order.ShippingAddress.City;
paymentDetails.ShipToAddress.StateOrProvince =
order.ShippingAddress.StateOrRegion;
paymentDetails.ShipToAddress.Country =
(CountryCodeType)Enum.Parse(typeof(CountryCodeType), order.ShippingAddress.Country);
paymentDetails.ShipToAddress.CountrySpecified = true;
paymentDetails.ShipToAddress.PostalCode =
order.ShippingAddress.PostalCode;
#endregion
#region Load Individual Items
//Add the individual items if they are available
//This will also add nice line item entries to the PayPal invoice - good for customers!
OrderItemCollection orderItemCollection = order.OrderItemRecords();
if(orderItemCollection != null) {
if(orderItemCollection.Count > 0) {
paymentDetails.PaymentDetailsItem = new PaymentDetailsItemType[orderItemCollection.Count];
PaymentDetailsItemType[] paymentDetailsItems = new PaymentDetailsItemType[orderItemCollection.Count];
PaymentDetailsItemType item = null;
for(int i = 0;i < orderItemCollection.Count;i++) {
item = new PaymentDetailsItemType();
string sku = orderItemCollection[i].Sku.Trim();
if(sku.Length > 127) {
sku = sku.Substring(0, 126);
}
item.Name = orderItemCollection[i].Name;
item.Number = sku;
item.Amount = GetBasicAmount(decimal.Round(orderItemCollection[i].PricePaid, currency.CurrencyDecimals));
item.Quantity = orderItemCollection[i].Quantity.ToString();
item.Tax = GetBasicAmount(decimal.Round(orderItemCollection[i].ItemTax, currency.CurrencyDecimals));
paymentDetailsItems[i] = item;
}
paymentDetails.PaymentDetailsItem = paymentDetailsItems;
}
}
#endregion
//Now load it all up
expressCheckoutPayment.DoExpressCheckoutPaymentRequest = expressCheckoutPaymentRequest;
expressCheckoutPayment.DoExpressCheckoutPaymentRequest.DoExpressCheckoutPaymentRequestDetails = expressCheckoutPaymentRequestDetails;
expressCheckoutPayment.DoExpressCheckoutPaymentRequest.DoExpressCheckoutPaymentRequestDetails.PaymentDetails[0] = paymentDetails;
#region Charge and Validation
//Finally, send it
DoExpressCheckoutPaymentResponseType expressCheckoutPaymentResponse =
payPalAPIAASoapBinding.DoExpressCheckoutPayment(expressCheckoutPayment);
//Validate the response
string errorList = ValidateResponse(expressCheckoutPaymentResponse);
// if(expressCheckoutPaymentResponse.Ack != AckCodeType.Success && expressCheckoutPaymentResponse.Ack != AckCodeType.SuccessWithWarning) {
if(IsValidResponse(expressCheckoutPaymentResponse.Ack)){
if(!string.IsNullOrEmpty(errorList)) {
throw new PayPalServiceException(errorList);
}
}
#endregion
#region Transaction
transaction = new Transaction();
transaction.OrderId = order.OrderId;
if(!authorizeOnly) {
transaction.TransactionTypeDescriptorId = (int)TransactionType.Charge;
}
else {
transaction.TransactionTypeDescriptorId = (int)TransactionType.Authorization;
}
transaction.PaymentMethod = order.CreditCardType.ToString();
transaction.GatewayName = PAYPAL_EXPRESSCHECKOUT;
string gatewayResponse = expressCheckoutPaymentResponse.Ack.ToString();
if(expressCheckoutPaymentResponse.DoExpressCheckoutPaymentResponseDetails.PaymentInfo[0].PaymentStatus == PaymentStatusCodeType.Pending) {
gatewayResponse += "::Pending";
}
transaction.GatewayResponse = gatewayResponse;
transaction.GatewayTransactionId = expressCheckoutPaymentResponse.DoExpressCheckoutPaymentResponseDetails.PaymentInfo[0].TransactionID;
transaction.GrossAmount = Convert.ToDecimal(expressCheckoutPaymentResponse.DoExpressCheckoutPaymentResponseDetails.PaymentInfo[0].GrossAmount.Value);
transaction.FeeAmount = expressCheckoutPaymentResponse.DoExpressCheckoutPaymentResponseDetails.PaymentInfo[0].FeeAmount != null ? Convert.ToDecimal(
expressCheckoutPaymentResponse.DoExpressCheckoutPaymentResponseDetails.PaymentInfo[0].FeeAmount.Value) : 0M;
transaction.TransactionDate = DateTime.Now;
transaction.GatewayErrors = errorList;
transaction.Save("System");
#endregion
return transaction;
}
示例4: DoDirectPayment
//.........这里部分代码省略.........
if (order.BillingAddress.FirstName == null)
throw new ArgumentException("BillingAddress.FirstName is missing " + order.PaymentMethod + " " + order.CreditCardType);
directPaymentRequestDetails.CreditCard.CardOwner.PayerName.FirstName = order.BillingAddress.FirstName;
directPaymentRequestDetails.CreditCard.CardOwner.PayerName.LastName = order.BillingAddress.LastName;
CountryCodeType customerCountry = CountryCodeType.US;
if (order.BillingAddress.Country != CountryCodeType.US.ToString()) {
if (Enum.IsDefined(typeof(CountryCodeType), order.BillingAddress.Country)) {
customerCountry = (CountryCodeType)Enum.Parse(typeof(CountryCodeType), order.BillingAddress.Country);
}
}
directPaymentRequestDetails.CreditCard.CardOwner.PayerCountry = customerCountry;
//Load up the Card Owner Address information
directPaymentRequestDetails.CreditCard.CardOwner.Address.Country = customerCountry;
directPaymentRequestDetails.CreditCard.CardOwner.Address.CountrySpecified = true;
directPaymentRequestDetails.CreditCard.CardOwner.Address.Street1 = order.BillingAddress.Address1;
directPaymentRequestDetails.CreditCard.CardOwner.Address.Street2 = order.BillingAddress.Address2;
directPaymentRequestDetails.CreditCard.CardOwner.Address.CityName = order.BillingAddress.City;
directPaymentRequestDetails.CreditCard.CardOwner.Address.StateOrProvince = order.BillingAddress.StateOrRegion;
directPaymentRequestDetails.CreditCard.CardOwner.Address.PostalCode = order.BillingAddress.PostalCode;
//Load up the Credit Card information
directPaymentRequestDetails.CreditCard.CreditCardNumber = order.CreditCardNumber;
CreditCardTypeType creditCardType = CreditCardTypeType.Visa;
switch (order.CreditCardType) {
case CreditCardType.MasterCard:
creditCardType = CreditCardTypeType.MasterCard;
break;
case CreditCardType.Amex:
creditCardType = CreditCardTypeType.Amex;
break;
case CreditCardType.Maestro:
creditCardType = CreditCardTypeType.Switch;
break;
case CreditCardType.Solo:
creditCardType = CreditCardTypeType.Solo;
break;
}
directPaymentRequestDetails.CreditCard.CreditCardType = creditCardType;
directPaymentRequestDetails.CreditCard.CreditCardTypeSpecified = true;
directPaymentRequestDetails.CreditCard.IssueNumber = order.CreditCardIssueNumber;
if (order.CreditCardStartMonth > 0) {
directPaymentRequestDetails.CreditCard.StartMonth = order.CreditCardStartMonth;
directPaymentRequestDetails.CreditCard.StartMonthSpecified = true;
}
if (order.CreditCardStartYear > 0) {
directPaymentRequestDetails.CreditCard.StartYear = order.CreditCardStartYear;
directPaymentRequestDetails.CreditCard.StartYearSpecified = true;
}
directPaymentRequestDetails.CreditCard.ExpMonth = order.CreditCardExpirationMonth;
directPaymentRequestDetails.CreditCard.ExpMonthSpecified = true;
directPaymentRequestDetails.CreditCard.ExpYear = order.CreditCardExpirationYear;
directPaymentRequestDetails.CreditCard.ExpYearSpecified = true;
directPaymentRequestDetails.CreditCard.CVV2 = order.CreditCardSecurityNumber;
#endregion
directPaymentReq.DoDirectPaymentRequest.DoDirectPaymentRequestDetails = directPaymentRequestDetails;
#region Charge and Validation
//Finally, send it
DoDirectPaymentResponseType directPaymentResponse =
payPalAPIAASoapBinding.DoDirectPayment(directPaymentReq);
//Validate the response
string errorList = ValidateResponse(directPaymentResponse);
if (IsValidResponse(directPaymentResponse.Ack)){
if (!string.IsNullOrEmpty(errorList)) {
throw new PayPalServiceException(errorList);
}
}
#endregion
#region Transaction
transaction = new Transaction();
transaction.OrderId = order.OrderId;
if(!authorizeOnly) {
transaction.TransactionTypeDescriptorId = (int)TransactionType.Charge;
}
else {
transaction.TransactionTypeDescriptorId = (int)TransactionType.Authorization;
}
transaction.PaymentMethod = order.CreditCardType.ToString();
transaction.GatewayName = PAYPALPRO;
transaction.GatewayResponse = directPaymentResponse.Ack.ToString();
//These "Not Available"'s shouldn't trip off, but if PayPal is being flaky (like it is today), then this will allow the transaction to be saved.
transaction.GatewayTransactionId = !string.IsNullOrEmpty(directPaymentResponse.TransactionID) ? directPaymentResponse.TransactionID : Strings.ResourceManager.GetString("lblNotAvailable");
transaction.AVSCode = !string.IsNullOrEmpty(directPaymentResponse.AVSCode) ? directPaymentResponse.AVSCode : Strings.ResourceManager.GetString("lblNotAvailable");
transaction.CVV2Code = !string.IsNullOrEmpty(directPaymentResponse.CVV2Code) ? directPaymentResponse.CVV2Code : Strings.ResourceManager.GetString("lblNotAvailable");
if (directPaymentResponse.Amount != null) {//try to get it from PayPal
transaction.GrossAmount = Convert.ToDecimal(directPaymentResponse.Amount.Value);
}
else {//but if it fails, then use the Order total
transaction.GrossAmount = order.Total;
}
transaction.TransactionDate = DateTime.Now;
transaction.GatewayErrors = errorList;
transaction.Save("System");
#endregion
return transaction;
}
示例5: Charge
//.........这里部分代码省略.........
if (order.ShippingAddress != null) {
sb.AppendFormat("&x_ship_to_first_name={0}", HttpUtility.UrlEncode(order.ShippingAddress.FirstName));
sb.AppendFormat("&x_ship_to_last_name={0}", HttpUtility.UrlEncode(order.ShippingAddress.LastName));
sb.AppendFormat("&x_ship_to_address={0}", HttpUtility.UrlEncode(order.ShippingAddress.Address1));
sb.AppendFormat("&x_ship_to_city={0}", HttpUtility.UrlEncode(order.ShippingAddress.City));
sb.AppendFormat("&x_ship_to_state={0}", HttpUtility.UrlEncode(order.ShippingAddress.StateOrRegion));
sb.AppendFormat("&x_ship_to_zip={0}", HttpUtility.UrlEncode(order.ShippingAddress.PostalCode));
sb.AppendFormat("&x_ship_to_country={0}", HttpUtility.UrlEncode(order.ShippingAddress.Country));
}
#endregion
#region Line Items
AppendLineItems(order, sb, currency);
#endregion
#region Credit Card Info
//x_exp_date
//x_card_num
//x_card_code
string expDate = string.Empty;
if (order.CreditCardExpirationMonth < 10) {
expDate = "0" + order.CreditCardExpirationMonth.ToString();
}
else {
expDate = order.CreditCardExpirationMonth.ToString();
}
if (order.CreditCardExpirationYear > 99) {
expDate += order.CreditCardExpirationYear.ToString().Substring(2, 2);
}
else {
expDate += order.CreditCardExpirationYear.ToString();
}
sb.AppendFormat("&x_exp_date={0}", HttpUtility.UrlEncode(expDate));
sb.AppendFormat("&x_card_num={0}", HttpUtility.UrlEncode(order.CreditCardNumber));
sb.AppendFormat("&x_card_code={0}", HttpUtility.UrlEncode(order.CreditCardSecurityNumber));
//If the charge fails the first time thru, then we will have some data populated, so we need to try to remove it first
if (order.ExtendedProperties.Contains("Validator")) {
order.ExtendedProperties.Remove("Validator");
}
if (order.ExtendedProperties.Contains("ExpDate")) {
order.ExtendedProperties.Remove("ExpDate");
}
//now, add them back in
order.ExtendedProperties.Add("Validator", order.CreditCardNumber.ToString().Substring((order.CreditCardNumber.Length-4)));
order.ExtendedProperties.Add("ExpDate", expDate);
order.AdditionalProperties = order.ExtendedProperties.ToXml();
order.Save("System");
#endregion
#region Charge It
//postData = HttpUtility.UrlEncode(sb.ToString());
postData = sb.ToString();
string response = CoreUtility.SendRequestByPost(AuthorizeServiceUtility.GetAuthorizeServiceEndpoint(this.IsLive), postData);
#endregion
#region Check it and Build up the Transaction
string[] output = response.Split('|');
int counter = 1;//Start @ 1 to keep in sync with docs
System.Collections.Hashtable vars = new System.Collections.Hashtable();
foreach (string var in output) {
vars.Add(counter, var);
counter += 1;
}
Transaction transaction = null;
string responseCode = vars[1].ToString();
if ((responseCode == "2") || (responseCode == "3")) {
throw new AuthorizeNetServiceException(vars[4].ToString());
}
else {
transaction = new Transaction();
transaction.OrderId = order.OrderId;
transaction.TransactionTypeDescriptorId = (int)TransactionType.Charge;
transaction.PaymentMethod = order.CreditCardType.ToString();
transaction.GatewayName = AUTHORIZENET;
transaction.GatewayResponse = vars[1].ToString();
transaction.GatewayTransactionId = vars[7].ToString();
transaction.AVSCode = vars[6].ToString();
transaction.CVV2Code = vars[39].ToString();
decimal grossAmount = 0.00M;
bool isParsed = decimal.TryParse(vars[10].ToString(), out grossAmount);
transaction.GrossAmount = grossAmount;
transaction.TransactionDate = DateTime.Now;
transaction.Save("System");
}
#endregion
return transaction;
}
示例6: Insert
public void Insert(int OrderId,int TransactionTypeDescriptorId,string PaymentMethod,string GatewayName,string GatewayResponse,string GatewayTransactionId,string AVSCode,string CVV2Code,decimal GrossAmount,decimal NetAmount,decimal FeeAmount,DateTime TransactionDate,string GatewayErrors,string CreatedBy,DateTime CreatedOn,string ModifiedBy,DateTime ModifiedOn)
{
Transaction item = new Transaction();
item.OrderId = OrderId;
item.TransactionTypeDescriptorId = TransactionTypeDescriptorId;
item.PaymentMethod = PaymentMethod;
item.GatewayName = GatewayName;
item.GatewayResponse = GatewayResponse;
item.GatewayTransactionId = GatewayTransactionId;
item.AVSCode = AVSCode;
item.CVV2Code = CVV2Code;
item.GrossAmount = GrossAmount;
item.NetAmount = NetAmount;
item.FeeAmount = FeeAmount;
item.TransactionDate = TransactionDate;
item.GatewayErrors = GatewayErrors;
item.CreatedBy = CreatedBy;
item.CreatedOn = CreatedOn;
item.ModifiedBy = ModifiedBy;
item.ModifiedOn = ModifiedOn;
item.Save(UserName);
}
示例7: Insert
public void Insert(decimal? Amount,int? GiftKey,DateTime? InitDate,DateTime? CollectedDate,string TxnId,int? TxStatus,string Pakey,string ReceiverEmail)
{
Transaction item = new Transaction();
item.Amount = Amount;
item.GiftKey = GiftKey;
item.InitDate = InitDate;
item.CollectedDate = CollectedDate;
item.TxnId = TxnId;
item.TxStatus = TxStatus;
item.Pakey = Pakey;
item.ReceiverEmail = ReceiverEmail;
item.Save(UserName);
}
示例8: RefundStandard
/// <summary>
/// Refunds the specified transaction.
/// </summary>
/// <param name="transaction">The transaction.</param>
/// <param name="refundedOrder">The refunded order.</param>
/// <param name="userName">Name of the user.</param>
public static void RefundStandard(Transaction transaction, Order refundedOrder, string userName)
{
Order order = new Order(transaction.OrderId);
Transaction refundTransaction = new Transaction();
//refundTransaction.OrderId = transaction.OrderId;
refundTransaction.TransactionTypeDescriptorId = (int)TransactionType.Refund;
refundTransaction.PaymentMethod = PAYPAL;
refundTransaction.GatewayName = PAYPAL_STANDARD;
refundTransaction.GatewayResponse = SUCCESS;
refundTransaction.GatewayTransactionId = CoreUtility.GenerateRandomString(16);
refundTransaction.GrossAmount = refundedOrder.Total;
refundTransaction.NetAmount = 0.00M;
refundTransaction.FeeAmount = 0.00M;
refundTransaction.TransactionDate = DateTime.Now;
//refundTransaction.Save(userName);
refundedOrder.Save(userName);
//set the orderid for the refund
foreach(OrderItem orderItem in refundedOrder.OrderItemCollection) {
orderItem.OrderId = refundedOrder.OrderId;
}
refundedOrder.OrderItemCollection.SaveAll(userName);
//set the orderId to the refunded orderId
refundTransaction.OrderId = refundedOrder.OrderId;
refundTransaction.Save(userName);
Guid userGuid = new Guid(Membership.GetUser(order.UserName).ProviderUserKey.ToString());
DownloadCollection downloadCollection;
foreach(OrderItem orderItem in refundedOrder.OrderItemCollection) {
//put the stock back
Sku sku = new Sku(Sku.Columns.SkuX, orderItem.Sku);
sku.Inventory = sku.Inventory + orderItem.Quantity;
sku.Save(userName);
ProductCache.RemoveSKUFromCache(orderItem.Sku);
//remove the access control
downloadCollection = new ProductController().FetchAssociatedDownloadsByProductIdAndForPurchase(orderItem.ProductId);
if (downloadCollection.Count > 0) {
foreach (Download download in downloadCollection) {
new DownloadAccessControlController().Delete(userGuid, download.DownloadId);
}
}
}
if(refundedOrder.Total == order.Total) {
order.OrderStatusDescriptorId = (int)OrderStatus.OrderFullyRefunded;
}
else {
order.OrderStatusDescriptorId = (int)OrderStatus.OrderPartiallyRefunded;
}
order.Save(userName);
//Add an OrderNote
OrderNote orderNote = new OrderNote();
orderNote.OrderId = order.OrderId;
orderNote.Note = Strings.ResourceManager.GetString(ORDER_REFUNDED);
orderNote.Save(userName);
//send off the notifications
MessageService messageService = new MessageService();
messageService.SendOrderRefundToCustomer(refundedOrder);
}
示例9: CommitStandardTransaction
/// <summary>
/// Commits the standard transaction.
/// </summary>
/// <param name="order">The order.</param>
/// <param name="transactionId">The transaction id.</param>
/// <param name="grossAmount">The gross amount.</param>
/// <returns></returns>
public static Transaction CommitStandardTransaction(Order order, string transactionId, decimal grossAmount)
{
order.OrderStatusDescriptorId = (int)OrderStatus.ReceivedPaymentProcessingOrder;
order.Save(SYSTEM);
Transaction transaction = new Transaction();
transaction.OrderId = order.OrderId;
transaction.TransactionTypeDescriptorId = (int)TransactionType.Charge;
transaction.PaymentMethod = PAYPAL;
transaction.GatewayName = PAYPAL_STANDARD;
transaction.GatewayResponse = SUCCESS;
transaction.GatewayTransactionId = transactionId;
transaction.GrossAmount = grossAmount;
transaction.TransactionDate = DateTime.UtcNow;
transaction.Save(SYSTEM);
try {
//Adjust the Inventory
Sku sku;
foreach (OrderItem orderItem in order.OrderItemCollection) {
sku = new Sku("Sku", orderItem.Sku);
sku.Inventory = sku.Inventory - orderItem.Quantity;
sku.Save("System");
ProductCache.RemoveSKUFromCache(orderItem.Sku);
}
//Send out the messages
MessageService messageService = new MessageService();
messageService.SendOrderReceivedNotificationToCustomer(order);
messageService.SendOrderReceivedNotificationToMerchant(order);
}
catch (Exception ex) {
//swallow the exception here because the transaction is saved
//and, while this is an inconvenience, it's not critical
Logger.Error(typeof(OrderController).Name + ".CommitStandardTransaction", ex);
}
return transaction;
}