public RespConsumePrepaidCard UsePrepaidCard(IPTV2Entities context, System.Guid userId, Transaction transaction) { RespConsumePrepaidCard result = null; InitializeServiceClient(); try { // validate user GomsException validationResult = UserValidation(context, userId); if (!(validationResult is GomsSuccess)) { throw validationResult; } var user = context.Users.Find(userId); if ((transaction == null) || (transaction.TransactionId == 0)) { throw new GomsInvalidTransactionException(); } if (transaction is PpcPaymentTransaction | transaction is PpcReloadTransaction) { // prepare request var req = new ReqConsumePrepaidCard { UID = ServiceUserId, PWD = ServicePassword, Email = user.EMail, CustomerId = (int)user.GomsCustomerId, ServiceId = (int)user.GomsServiceId, SubsidiaryId = (int)user.GomsSubsidiaryId, WalletId = (int)user.GomsWalletId, PhoenixId = transaction.TransactionId, TransactionDate = transaction.Date, Amount = (double)transaction.Amount // TODO: use transactionID or use base number // PhoenixId=(int)(DateTime.Now.Ticks - int.MaxValue), }; if (transaction is PpcReloadTransaction) { var reloadTransaction = (PpcReloadTransaction)transaction; req.PPCPin = reloadTransaction.ReloadPpc.Pin; req.PPCSerial = reloadTransaction.ReloadPpc.SerialNumber; req.CurrencyId = (int)context.Currencies.Find(reloadTransaction.ReloadPpc.Currency).GomsId; } else if (transaction is PpcPaymentTransaction) { var paymentTransaction = (PpcPaymentTransaction)transaction; int currencyId = 0; string curr = transaction.Currency; if (transaction.Currency == "---") { currencyId = (int)paymentTransaction.User.Country.Currency.GomsId; curr = paymentTransaction.User.Country.CurrencyCode; } else { currencyId = (int)context.Currencies.Find(paymentTransaction.Currency).GomsId; } req.PPCPin = paymentTransaction.SubscriptionPpc.Pin; req.PPCSerial = paymentTransaction.SubscriptionPpc.SerialNumber; req.CurrencyId = currencyId; var item = paymentTransaction.Purchase.PurchaseItems.FirstOrDefault(); if (item != null) { var endDate = item.EntitlementRequest.EndDate; var startDate = endDate; switch (item.SubscriptionProduct.DurationType.ToUpper()) { case "D": { startDate = endDate.AddDays(item.SubscriptionProduct.Duration * -1); break; }; case "M": { startDate = endDate.AddMonths(item.SubscriptionProduct.Duration * -1); break; }; case "Y": { startDate = endDate.AddYears(item.SubscriptionProduct.Duration * -1); break; }; default: { break; } } req.SubscriptionStartDate = startDate; req.SubscriptionEndDate = endDate; } } else { throw new GomsInvalidTransactionTypeException(); } try { result = _serviceClient.ConsumePrepaidCard(req); if (result.IsSuccess) { transaction.GomsTransactionId = result.TransactionId; transaction.GomsTransactionDate = DateTime.Now; context.SaveChanges(); } } catch (Exception e) { throw new GomsServiceCallException(e.Message); } } else { throw new GomsInvalidTransactionTypeException(); } } catch (GomsException e) { result = new RespConsumePrepaidCard { IsSuccess = false, StatusCode = e.StatusCode, StatusMessage = e.StatusMessage }; } return (result); }
private static void SendConfirmationEmails(User user, User recipient, Transaction transaction, string ProductNameBought, Product product, DateTime endDt, DateTime registDt, string mode, bool isGift, bool isExtension, bool isAutoRenew = false, DateTime? autoRenewReminderDate = null) { if (!HttpContext.Current.Request.IsLocal) { //Send email string emailBody = String.Empty; string mailSubject = String.Empty; string toEmail = String.Empty; string type = "Subscription"; if (isGift) { emailBody = String.Format(GlobalConfig.GiftingSenderBodyTextOnly, transaction.TransactionId, product.Name, registDt.ToString("MM/dd/yyyy hh:mm:ss tt"), transaction.Amount.ToString("F2"), transaction.Currency, mode, transaction.Reference); mailSubject = String.Format("{0} {1} has received your TFC.tv gift", recipient.FirstName, recipient.LastName); toEmail = user.EMail; //Send to recipient try { string recipientEmailBody = String.Format(GlobalConfig.GiftingRecipientBodyTextOnly, recipient.FirstName, user.FirstName, user.LastName, ProductNameBought, endDt.ToString("MM/dd/yyyy hh:mm:ss tt"), GlobalConfig.baseUrl, user.UserId); string recipientMailSubject = String.Format("{0} {1} has sent you a TFC.tv gift", user.FirstName, user.LastName); string recipientToEmail = recipient.EMail; if (!String.IsNullOrEmpty(recipientToEmail)) MyUtility.SendEmailViaSendGrid(recipientToEmail, GlobalConfig.NoReplyEmail, recipientMailSubject, recipientEmailBody, MailType.TextOnly, recipientEmailBody); } catch (Exception) { } } else { mailSubject = String.Format("You are now subscribed to {0}", ProductNameBought); if (isAutoRenew) { type = "Subscription - On Automatic Renewal*"; } if (isExtension) { type = "Subscription Extension"; if (isAutoRenew) type = "Subscription Extension- On Automatic Renewal*"; mailSubject = String.Format("Your {0} has been extended", ProductNameBought); } toEmail = user.EMail; } try { if (!String.IsNullOrEmpty(toEmail)) { MyUtility.SendReceiptEmail(ProductNameBought, user, endDt.ToString("MM/dd/yyyy"), mailSubject, transaction.TransactionId.ToString(), registDt.ToString("MM/dd/yyyy hh:mm:ss tt"), transaction.Amount.ToString("F2"), transaction.Currency, type, mode, transaction.Reference,isExtension); } } catch (Exception) { } } }
private static void SendConfirmationEmails(User user, User recipient, Transaction transaction, string ProductNameBought, Product product, DateTime endDt, DateTime registDt, string mode, DateTime? autoRenewReminderDate = null, string GomsError = null) { if (isSendEmailEnabled) { string emailBody = String.Empty; string mailSubject = String.Empty; string toEmail = String.Empty; emailBody = String.Format(ExtendSubscriptionBodyWithAutoRenewTextOnly, user.FirstName, ProductNameBought, endDt.ToString("MM/dd/yyyy hh:mm:ss tt"), transaction.TransactionId, product.Name, registDt.ToString("MM/dd/yyyy hh:mm:ss tt"), transaction.Amount.ToString("F2"), transaction.Currency, mode, transaction.Reference, ((DateTime)autoRenewReminderDate).ToString("MMMM dd, yyyy")); mailSubject = String.Format("Your {0} has been extended", ProductNameBought); toEmail = user.EMail; if (!String.IsNullOrEmpty(GomsError)) { emailBody = String.Format(AutoRenewFailureBodyTextOnly, user.FirstName, ProductNameBought, GomsError); mailSubject = "Unable to Auto-Renew your TFC.tv Subscription"; } try { if (!String.IsNullOrEmpty(toEmail)) SendEmailViaSendGrid(toEmail, NoReplyEmail, mailSubject, emailBody, MailType.TextOnly, emailBody); } catch (Exception e) { throw new Exception(String.Format("SendGrid: {0}", e.Message)); } } }
public static string GetTransactionType(Transaction transaction) { string result = String.Empty; if (transaction is PaymentTransaction) { if (transaction is CreditCardPaymentTransaction) result = "Credit Card"; else if (transaction is PaypalPaymentTransaction) result = "PayPal"; else if (transaction is PpcPaymentTransaction) result = "Prepaid Card/ePIN"; else if (transaction is WalletPaymentTransaction) result = "E-Wallet"; } else if (transaction is ReloadTransaction) { if (transaction is CreditCardReloadTransaction) result = "Credit Card"; else if (transaction is PaypalReloadTransaction) result = "PayPal"; else if (transaction is PpcReloadTransaction) result = "Prepaid Card/ePIN"; else if (transaction is SmartPitReloadTransaction) result = "SmartPit"; } return result; }