static public void CreditCardPurchase() { var context = new IPTV2Entities(); var gomsService = new GomsTfcTv(); var user = context.Users.FirstOrDefault(u => u.EMail == "*****@*****.**"); if (user != null) { var product = (SubscriptionProduct)context.Products.Find(1); var currency = user.Country.Currency; var productPrice = product.ProductPrices.FirstOrDefault(pp => pp.CurrencyCode == user.Country.CurrencyCode); var amount = productPrice.Amount; // create purchase item var purchaseItem = new PurchaseItem { Currency = currency.Code, SubscriptionProduct = product, Price = productPrice.Amount, User = user, RecipientUserId = user.UserId }; // create purchase var purchase = new Purchase { Date = DateTime.Now, User = user, PurchaseItems = new List<PurchaseItem> { purchaseItem }, }; // create transaction var transaction = new CreditCardPaymentTransaction { Date = DateTime.Now, Purchase = purchase, Currency = currency.Code, Amount = amount, }; var resp = gomsService.CreateOrderViaCreditCard(context, user.UserId, transaction, GetCreditCard()); if (resp.IsSuccess) { // YEY } } }
private Purchase CreatePurchase(DateTime registDt, string remarks) { Purchase purchase = new Purchase() { Date = registDt, Remarks = remarks }; return purchase; }
private static ErrorCodes PayViaPrepaidCard() { try { // setup test variables var context = new IPTV2Entities(); int offeringId = 2; // TFC.tv var currencyCode = "USD"; int productId = 2; // TFC.tv Premium 10 Days SubscriptionProductType subscriptionType = SubscriptionProductType.Package; System.Guid userId = new System.Guid("896CA57E-67BC-4A28-86EA-A52E5426B693"); // albin's account string serial = "1"; string pin = "72656"; var testPPC = context.Ppcs.FirstOrDefault(p => p.SerialNumber == serial); if (testPPC != null) { context.Ppcs.Remove(testPPC); } var thisUser = context.Users.FirstOrDefault(u => u.UserId == userId); foreach (var t in thisUser.Transactions) { if (t is PpcPaymentTransaction) { thisUser.Transactions.Remove(t); } } context.SaveChanges(); var newPpc = new SubscriptionPpc { SerialNumber = serial, Pin = pin, Amount = 4.99m, Currency = "USD", Duration = 10, DurationType = "d", PpcProductId = 523, ProductId = productId, ExpirationDate = DateTime.Now.AddYears(1) }; context.Ppcs.Add(newPpc); context.SaveChanges(); // end setup test variables DateTime registDt = DateTime.Now; User user = context.Users.FirstOrDefault(u => u.UserId == userId); Offering offering = context.Offerings.FirstOrDefault(o => o.OfferingId == offeringId); Product product = context.Products.FirstOrDefault(p => p.ProductId == productId); ProductPrice priceOfProduct = product.ProductPrices.FirstOrDefault(p => p.CurrencyCode == currencyCode); Ppc ppc = context.Ppcs.FirstOrDefault(p => p.SerialNumber == serial); if (ppc == null) //Serial does not exist return ErrorCodes.IsInvalidPpc; if (!(ppc.SerialNumber == serial && ppc.Pin == pin)) //Invalid serial/pin combination return ErrorCodes.IsInvalidCombinationPpc; if (ppc.UserId != null) // Ppc has already been used return ErrorCodes.IsUsedPpc; if (!(ppc is SubscriptionPpc)) // Ppc is not of type Subscription return ErrorCodes.IsReloadPpc; if (registDt > ppc.ExpirationDate) // Ppc is expired return ErrorCodes.IsExpiredPpc; SubscriptionPpc sPpc = (SubscriptionPpc)ppc; if (sPpc.ProductId != product.ProductId) // Ppc product is invalid. return ErrorCodes.IsProductIdInvalidPpc; if (ppc.Currency.Trim() != currencyCode) // Ppc not valid in your country return ErrorCodes.IsNotValidInCountryPpc; if (ppc.Amount != priceOfProduct.Amount) // Ppc is of invalid amount return ErrorCodes.IsNotValidAmountPpc; Purchase purchase = new Purchase() { Date = registDt, Remarks = "Payment via Ppc" }; user.Purchases.Add(purchase); PurchaseItem item = new PurchaseItem() { RecipientUserId = userId, ProductId = product.ProductId, Price = priceOfProduct.Amount, Currency = priceOfProduct.Currency.Code, Remarks = product.Name }; purchase.PurchaseItems.Add(item); PpcPaymentTransaction transaction = new PpcPaymentTransaction() { Currency = priceOfProduct.Currency.Code, Reference = serial.ToUpper(), Amount = purchase.PurchaseItems.Sum(p => p.Price), Product = product, Purchase = purchase, // SubscriptionPpc = sPpc, SubscriptionPpcId = ppc.PpcId, Date = registDt }; user.Transactions.Add(transaction); // purchase.PaymentTransaction.Add(transaction); // product.PpcPaymentTransactions.Add(transaction); //item.SubscriptionProduct = (SubscriptionProduct)product; //switch (subscriptionType) //{ // case SubscriptionProductType.Show: // break; // case SubscriptionProductType.Package: // if (product is PackageSubscriptionProduct) // { // registDt = registDt.AddMinutes(1); // // DateAndTime.DateAdd(DateInterval.Minute, 1, registDt); // PackageSubscriptionProduct subscription = (PackageSubscriptionProduct)product; // //EntitlementRequest request = new EntitlementRequest() // //{ // // DateRequested = registDt, // // EndDate = MyUtility.getEntitlementEndDate(subscription.Duration, subscription.DurationType, registDt), // // Product = product, // // Source = String.Format("{0}-{1}", "Ppc", ppc.PpcId.ToString()), // // ReferenceId = purchase.PurchaseId.ToString() // //}; // //user.EntitlementRequests.Add(request); // foreach (var package in subscription.Packages) // { // PackageEntitlement currentPackage = user.PackageEntitlements.FirstOrDefault(p => p.PackageId == package.PackageId); // DateTime endDate = registDt; // if (currentPackage != null) // { // currentPackage.EndDate = getEntitlementEndDate(subscription.Duration, subscription.DurationType, ((currentPackage.EndDate > registDt) ? currentPackage.EndDate : registDt)); // endDate = currentPackage.EndDate; // } // else // { // PackageEntitlement entitlement = new PackageEntitlement() // { // EndDate = getEntitlementEndDate(subscription.Duration, subscription.DurationType, registDt), // Package = (Package)package.Package, // OfferingId = offeringId // }; // user.PackageEntitlements.Add(entitlement); // } // EntitlementRequest request = new EntitlementRequest() // { // DateRequested = registDt, // EndDate = endDate, // Product = product, // Source = String.Format("{0}-{1}", "Ppc", ppc.PpcId.ToString()), // ReferenceId = purchase.PurchaseId.ToString() // }; // user.EntitlementRequests.Add(request); // } // } // break; // case SubscriptionProductType.Episode: break; //} ////update the Ppc //ppc.UserId = userId; //ppc.UsedDate = registDt; if (context.SaveChanges() > 0) { return ErrorCodes.Success; } return ErrorCodes.EntityUpdateError; } catch (Exception e) { Debug.WriteLine(e.InnerException); throw; } }