protected override void WriteTokenCore(XmlWriter writer, SecurityToken token) { if (writer == null) { throw new ArgumentNullException("writer"); } if (token == null) { throw new ArgumentNullException("token"); } CreditCardToken c = token as CreditCardToken; if (c != null) { writer.WriteStartElement(Constants.CreditCardTokenPrefix, Constants.CreditCardTokenName, Constants.CreditCardTokenNamespace); writer.WriteAttributeString(Constants.WsUtilityPrefix, Constants.Id, Constants.WsUtilityNamespace, token.Id); writer.WriteElementString(Constants.CreditCardNumberElementName, Constants.CreditCardTokenNamespace, c.CardInfo.CardNumber); writer.WriteElementString(Constants.CreditCardExpirationElementName, Constants.CreditCardTokenNamespace, XmlConvert.ToString(c.CardInfo.ExpirationDate, XmlDateTimeSerializationMode.Utc)); writer.WriteElementString(Constants.CreditCardIssuerElementName, Constants.CreditCardTokenNamespace, c.CardInfo.CardIssuer); writer.WriteEndElement(); writer.Flush(); } else { base.WriteTokenCore(writer, token); } }
public void TestCreditCardToken() { CreditCardToken token = GetCreditCardToken(); Assert.AreEqual(token.credit_card_id, "CARD-8PV12506MG6587946KEBHH4A"); Assert.AreEqual(token.payer_id, "009"); }
public void ConvertToJsonTest() { CreditCardToken token = GetCreditCardToken(); string expected = "{\"credit_card_id\":\"CARD-8PV12506MG6587946KEBHH4A\",\"payer_id\":\"009\",\"expire_month\":10,\"expire_year\":2015}"; string actual = token.ConvertToJson(); Assert.AreEqual(expected, actual); }
public void ConvertToJsonTest() { CreditCardToken target = GetCreditCardToken(); string expected = "{\"credit_card_id\":\"CARD-8PV12506MG6587946KEBHH4A\",\"payer_id\":\"009\"}"; string actual = target.ConvertToJson(); Assert.AreEqual(expected, actual); }
public void credit_card_idTest() { CreditCardToken target = GetCreditCardToken(); string expected = "CARD-8PV12506MG6587946KEBHH4A"; string actual = target.credit_card_id; Assert.AreEqual(expected, actual); }
public void payer_idTest() { CreditCardToken target = GetCreditCardToken(); string expected = "009"; string actual = target.payer_id; Assert.AreEqual(expected, actual); }
private CreditCardToken GetCreditCardToken() { CreditCardToken card = new CreditCardToken(); card.credit_card_id = "CARD-8PV12506MG6587946KEBHH4A"; card.payer_id = "009"; return(card); }
private CreditCardToken GetCreditCardToken() { CreditCardToken cardToken = new CreditCardToken(); cardToken.credit_card_id = "CARD-8PV12506MG6587946KEBHH4A"; cardToken.payer_id = "009"; cardToken.expire_month = 10; cardToken.expire_year = 2015; return(cardToken); }
public static CreditCardToken GetCreditCardToken() { CreditCardToken cardToken = new CreditCardToken { credit_card_id = "CARD-8PV12506MG6587946KEBHH4A", payer_id = "009", expire_month = 10, expire_year = 2015 }; return(cardToken); }
public void Post_ShouldCreateCreditCard() { #region data generation var rand = new Random(); var customer = new Customer { FullName = "Guilherme de castro Titschkoski", EmailAddress = "*****@*****.**" }; var customerRest = new CustomerRestClient(); var postedCustomer = customerRest.Post(customer); #endregion var creditCard = new CreditCardToken { Name = customer.FullName, Document = "41847645844", Customer = new Customer { ContactPhone = "19997323581", CustomerPayUId = postedCustomer.CustomerPayUId }, CreditCardType = new CreditCardType { Code = "MASTERCARD" }, Number = "5555666677778884", ExpirationDate = new DateTime(2021, 11, 01), Country = new Country { Code = "BR" }, Address = new Address { Line1 = "R Jose Paulino, 1875", Line2 = "APTO 41 B", Line3 = null, PostalCode = "13023102", City = "Campinas", State = "SP" } }; var sut = new CreditCardTokenRestClient(); var postedCreditCard = sut.Post(creditCard); var postedCreditCard2 = sut.Post(creditCard); Assert.IsNotNull(postedCreditCard.Token); Assert.IsNotNull(postedCreditCard2.Token); Assert.AreEqual <string>(postedCreditCard.Token, postedCreditCard2.Token); }
/// <summary> /// Handles the Click event of the lnkbtnPayNow control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param> protected void lnkbtnPayNow_Click(object sender, EventArgs e) { CreditCardToken companyCreditCardToken = FinanceSupport.GetCreditCardToken("Company", CompanyId); //Check whether payments are setup and display message if required. if (companyCreditCardToken == null) { popupNotification.Title = "Set up Payments"; ltrlNotification.Text = "Please set up payment details for the Company in order to make payments."; popupNotification.ShowPopup(); return; } popupMakePayment.ShowPopup(); }
internal CreditCardToken Put(CreditCardToken creditCard) { if (creditCard == null) { throw new ArgumentNullException("creditCard"); } var creditCardModel = creditCard.Map <CreditCardToken, Models.CreditCard>(); var request = this.CreateJsonRequest(string.Format("/rest/v4.3/creditCards/{0}", creditCardModel.Token), Method.PUT); request.AddBody(creditCardModel); var response = this.ExecuteRequest <Models.CreditCard>(request); return(response.Data.Map <Models.CreditCard, CreditCardToken>()); }
public static Payer CreditCard2RestApiPayer(this string cardId) { var creditCard = new CreditCardToken { credit_card_id = cardId }; var fundInstrument = new FundingInstrument { credit_card_token = creditCard }; var fundingInstrumentList = new List <FundingInstrument> { fundInstrument }; return(new Payer { funding_instruments = fundingInstrumentList, payment_method = BillingEnums.ePaymentMethods.Credit_Card.EnumToLowerString(), payer_info = new PayerInfo() }); }
/// <summary> /// Handles the NeedDataSource event of the gvProjects control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="Telerik.Web.UI.GridNeedDataSourceEventArgs"/> instance containing the event data.</param> protected void gvProjects_NeedDataSource(object sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e) { if (!StopProcessing) { #region Fill global variables required for data binding freeTrialCodeId = Support.GetCodeByValue("ProjectStatus", "FREETRIAL").CodeId; activeCodeId = Support.GetCodeByValue("ProjectStatus", "ACTIVE").CodeId; gracePeriodCodeId = Support.GetCodeByValue("ProjectStatus", "GRACEPERIOD").CodeId; paymentFailed = Support.GetCodeByValue("ProjectStatus", "PAYMENTFAILED").CodeId; suspendCodeId = Support.GetCodeByValue("ProjectStatus", "SUSPENDED").CodeId; closedCodeId = Support.GetCodeByValue("ProjectStatus", "CLOSED").CodeId; companyCreditCardToken = FinanceSupport.GetCreditCardToken("Company", CompanyId); #endregion Fill global variables required for data binding switch (ProjectsDisplayMode) { case ProjectsViewMode.ActiveProjects: projectStatusList.Add(freeTrialCodeId); projectStatusList.Add(activeCodeId); projectStatusList.Add(gracePeriodCodeId); projectStatusList.Add(paymentFailed); projectStatusList.Add(suspendCodeId); break; case ProjectsViewMode.ClosedProjects: projectStatusList.Add(closedCodeId); break; case ProjectsViewMode.AllProjects: projectStatusList.Add(freeTrialCodeId); projectStatusList.Add(activeCodeId); projectStatusList.Add(gracePeriodCodeId); projectStatusList.Add(paymentFailed); projectStatusList.Add(suspendCodeId); projectStatusList.Add(closedCodeId); break; } List <CompanyProjectDetails> projects = this.GetBL <FinanceBL>().GetCompanyProjectDetails(CompanyId, projectStatusList); gvProjects.DataSource = projects; } }
public ActionResult CompleteCheckout() { if (User.Identity.IsAuthenticated) { var packageId = Convert.ToInt32(Request.Form["packageId"]); var package = packageRepository.FindPackageById(packageId); var user = userRepository.FindUserByEmail(User.Identity.Name); var api = new StripeClient("2JeZdhBfTR4b1pMH4d9O0S58YtalPDbf"); var token = Request.Form["stripeToken"]; var creditCard = new CreditCardToken(token); dynamic response = api.CreateCharge(package.Costo, "usd", creditCard); if (response.Paid) { // Give the user the amount of lances in his bought package. user.LanceCreditBalance += package.CreditAmount; userRepository.SaveChanges(); // Save a record of the purchase of the package. BoughtPackage boughtPackage = new BoughtPackage(); boughtPackage.DateOfPurchase = DateTime.Now; boughtPackage.UserId = user.UserId; boughtPackage.LancePackageId = package.LancePackageId; boughtPackage.Total = package.Costo; packageRepository.CreateNewPackagePurchase(boughtPackage); packageRepository.SaveChanges(); // Redirect to purchase complete page. return(RedirectToAction("PurchaseComplete", "Shop")); } else { return(RedirectToAction("BuyLances", "Shop")); } } else { return(RedirectToAction("Login", "Account")); } }
/// <summary> /// Sets the UI settings. /// </summary> /// <param name="creditCardToken">The credit card token.</param> public void SetUISettings(CreditCardToken creditCardToken) { if (creditCardToken != null) { lnkSetUp.Visible = false; divPaymentDetailsSet.Visible = true; if (creditCardToken != null && creditCardToken.LastFourDigitsCreditCardNumber != null) { imgCreditCardNo.Attributes["title"] = "The last 4 digits of the credit card number you've used are XXXX-XXXX-XXXX-" + Utils.DecryptStringAES(creditCardToken.LastFourDigitsCreditCardNumber); imgCreditCardNo.Visible = true; } else { imgCreditCardNo.Visible = false; } lnkChange.Visible = true; spnSeperator.Visible = true; pnlExpander.Visible = false; if (DisplayMode == SetupCreditCardDetails.ViewMode.PricingPlan) { lnkSetUp.Text = pnlExpander.Visible ? "Hide" : "Set Up"; lnkChange.Text = pnlExpander.Visible ? "Hide" : "Change"; } litPaymentDetailsNotSet.Visible = false; } else { lnkSetUp.Visible = true; divPaymentDetailsSet.Visible = false; litPaymentDetailsNotSet.Visible = true; lnkChange.Visible = false; spnSeperator.Visible = false; pnlExpander.Visible = true; if (DisplayMode == SetupCreditCardDetails.ViewMode.PricingPlan) { paymentSetupDetails.Visible = false; } } }
public Payment CreatePayment(string email, PaymentMethod paymntMethod, string orderAmount, string orderDescription) { Payment pay = null; Amount amount = new Amount(); amount.currency = "USD"; amount.total = orderAmount; Transaction transaction = new Transaction(); transaction.amount = amount; transaction.description = orderDescription; List <Transaction> transactions = new List <Transaction>(); transactions.Add(transaction); FundingInstrument fundingInstrument = new FundingInstrument(); CreditCardToken creditCardToken = new CreditCardToken(); creditCardToken.credit_card_id = GetSignedInUserCreditCardID(email); fundingInstrument.credit_card_token = creditCardToken; List <FundingInstrument> fundingInstrumentList = new List <FundingInstrument>(); fundingInstrumentList.Add(fundingInstrument); Payer payer = new Payer(); payer.funding_instruments = fundingInstrumentList; payer.payment_method = paymntMethod.ToString(); Payment pyment = new Payment(); pyment.intent = "sale"; pyment.payer = payer; pyment.transactions = transactions; pay = pyment.Create(Api); return(pay); }
/// <summary> /// Processes the invoice. /// </summary> /// <param name="invoice">The invoice.</param> /// <param name="company">The company.</param> /// <param name="dataContext">The data context.</param> /// <returns></returns> private static bool ProcessInvoice(Invoice invoice, Data.Company company, StageBitzDB dataContext) { bool isSuccess = true; try { //Get the Payment History record which has not sent to the payment gateway. PaymentLog paymentLog = dataContext.PaymentLogs.Where(pl => pl.RelatedTableName == "Invoice" && pl.RelatedId == invoice.InvoiceID && pl.IsSentToPaymentGateway == false).FirstOrDefault(); //Get the TokenID of the Company to pass over to Payment gateway. CreditCardToken creditCardToken = (from ct in dataContext.CreditCardTokens where ct.RelatedTableName == "Company" && ct.RelatedId == company.CompanyId && ct.IsActive == true select ct).FirstOrDefault(); bool isPaymentSuccess = false; if (creditCardToken != null) { paymentLog.ReferenceNumber = Utils.GetSystemValue("ReferenceNumberPrefix") + paymentLog.PaymentLogId; //Make the payment via the payment gateway. //Multuply by 100 to send over to FatZebra. //Utils.DecryptStringAES(creditCardToken.Token) var response = Purchase.Create((int)(invoice.Amount * 100), Utils.DecryptStringAES(creditCardToken.Token), null, paymentLog.ReferenceNumber, Utils.GetSystemValue("SBServerIPAddress")); isPaymentSuccess = response.Successful && response.Result != null && response.Result.Successful; if (isPaymentSuccess) { //Update Invoice as Processed. invoice.InvoiceStatusCodeId = Utils.GetCodeByValue("InvoiceStatus", "PROCESSED").CodeId; //Create Receipt for the Invoice FinanceSupport.CreateReceipt(company.CompanyId, "Company", string.Format("Payment for Company {0}", company.CompanyName), invoice.Amount, invoice.Transaction.TransactionID, dataContext); } else { //Update Invoice as Failed. invoice.InvoiceStatusCodeId = Utils.GetCodeByValue("InvoiceStatus", "FAILED").CodeId; } //Update the Payment History record as Sent to payment gateway. paymentLog.IsSentToPaymentGateway = true; paymentLog.IsPaymentSuccess = isPaymentSuccess; if (response.Result != null) { paymentLog.ResponseId = response.Result.ID; } paymentLog.Description = GetPaymentGatewayLogDescription(response); paymentLog.CreditCardTokenId = creditCardToken.CreditCardTokenID; } else { paymentLog.Description = "Credit card details not provided."; //Update Invoice as Failed. invoice.InvoiceStatusCodeId = Utils.GetCodeByValue("InvoiceStatus", "FAILED").CodeId; } invoice.LastUpdateDate = Utils.Now; invoice.LastUpdatedBy = 0; paymentLog.LastUpdatedDate = Utils.Now; paymentLog.LastUpdatedByUserId = 0; isSuccess = isPaymentSuccess; } catch (Exception ex) { AgentErrorLog.WriteToErrorLog("Failed to Process the Invoice for CompanyId " + invoice.RelatedID); AgentErrorLog.HandleException(ex); isSuccess = false; } return(isSuccess); }
/// <summary> /// Initializes a new instance of the <see cref="CreditCardTokenBuilder"/> class. /// </summary> /// <param name="request">The request.</param> public CreditCardTokenBuilder(AbstractRequest request) { this.request = request; this.creditCardToken = new CreditCardToken(); }
protected void Page_Load(object sender, EventArgs e) { HttpContext CurrContext = HttpContext.Current; // ###CreditCard // A resource representing a credit card that can be // used to fund a payment. CreditCardToken credCardToken = new CreditCardToken(); credCardToken.credit_card_id = "CARD-5BT058015C739554AKE2GCEI"; // ###Details // Let's you specify details of a payment amount. Details details = new Details(); details.shipping = "1"; details.subtotal = "5"; details.tax = "1"; // ###Amount // Let's you specify a payment amount. Amount amnt = new Amount(); amnt.currency = "USD"; // Total must be equal to the sum of shipping, tax and subtotal. amnt.total = "7"; amnt.details = details; // ###Transaction // A transaction defines the contract of a // payment - what is the payment for and who // is fulfilling it. Transaction is created with // a `Payee` and `Amount` types Transaction tran = new Transaction(); tran.amount = amnt; tran.description = "This is the payment transaction description."; // The Payment creation API requires a list of // Transaction; add the created `Transaction` // to a List List <Transaction> transactions = new List <Transaction>(); transactions.Add(tran); // ###FundingInstrument // A resource representing a Payeer's funding instrument. // Use a Payer ID (A unique identifier of the payer generated // and provided by the facilitator. This is required when // creating or using a tokenized funding instrument) // and the `CreditCardDetails` FundingInstrument fundInstrument = new FundingInstrument(); fundInstrument.credit_card_token = credCardToken; // The Payment creation API requires a list of // FundingInstrument; add the created `FundingInstrument` // to a List List <FundingInstrument> fundingInstrumentList = new List <FundingInstrument>(); fundingInstrumentList.Add(fundInstrument); // ###Payer // A resource representing a Payer that funds a payment // Use the List of `FundingInstrument` and the Payment Method // as 'credit_card' Payer payr = new Payer(); payr.funding_instruments = fundingInstrumentList; payr.payment_method = "credit_card"; // ###Payment // A Payment Resource; create one using // the above types and intent as 'sale' Payment pymnt = new Payment(); pymnt.intent = "sale"; pymnt.payer = payr; pymnt.transactions = transactions; try { // ###AccessToken // Retrieve the access token from // OAuthTokenCredential by passing in // ClientID and ClientSecret // It is not mandatory to generate Access Token on a per call basis. // Typically the access token can be generated once and // reused within the expiry window string accessToken = new OAuthTokenCredential(ConfigManager.Instance.GetProperties()["ClientID"], ConfigManager.Instance.GetProperties()["ClientSecret"]).GetAccessToken(); // ### Api Context // Pass in a `ApiContext` object to authenticate // the call and to send a unique request id // (that ensures idempotency). The SDK generates // a request id if you do not pass one explicitly. APIContext apiContext = new APIContext(accessToken); // Use this variant if you want to pass in a request id // that is meaningful in your application, ideally // a order id. // String requestId = Long.toString(System.nanoTime(); // APIContext apiContext = new APIContext(accessToken, requestId )); // Create a payment by posting to the APIService // using a valid AccessToken // The return object contains the status; // Create a payment by posting to the APIService // using a valid AccessToken // The return object contains the status; Payment createdPayment = pymnt.Create(apiContext); CurrContext.Items.Add("ResponseJson", JObject.Parse(createdPayment.ConvertToJson()).ToString(Formatting.Indented)); } catch (PayPal.Exception.PayPalException ex) { CurrContext.Items.Add("Error", ex.Message); } CurrContext.Items.Add("RequestJson", JObject.Parse(pymnt.ConvertToJson()).ToString(Formatting.Indented)); Server.Transfer("~/Response.aspx"); }
protected override void RunSample() { // ### Api Context // Pass in a `APIContext` object to authenticate // the call and to send a unique request id // (that ensures idempotency). The SDK generates // a request id if you do not pass one explicitly. // See [Configuration.cs](/Source/Configuration.html) to know more about APIContext. var apiContext = Configuration.GetAPIContext(); // Items within a transaction. var item = new Item() { name = "Item Name", currency = "USD", price = "1", quantity = "5", sku = "sku" }; // A resource representing a credit card that can be used to fund a payment. var credCardToken = new CreditCardToken() { credit_card_id = "CARD-0F049886A57009534KRVL4LQ" }; var amnt = new Amount() { currency = "USD", total = "7", details = new Details() { shipping = "1", subtotal = "5", tax = "1" } }; // A transaction defines the contract of a // payment - what is the payment for and who // is fulfilling it. var tran = new Transaction() { amount = amnt, description = "This is the payment transaction description.", item_list = new ItemList() { items = new List <Item>() { item } } }; // A resource representing a Payer's funding instrument. For stored credit card payments, set the CreditCardToken field on this object. var fundInstrument = new FundingInstrument() { credit_card_token = credCardToken }; // A Payment Resource; create one using the above types and intent as 'sale' var pymnt = new Payment() { intent = "sale", payer = new Payer() { funding_instruments = new List <FundingInstrument>() { fundInstrument }, payment_method = "credit_card" }, transactions = new List <Transaction>() { tran } }; // ^ Ignore workflow code segment #region Track Workflow this.flow.AddNewRequest("Create credit card payment", pymnt); #endregion // Create a payment using a valid APIContext var createdPayment = pymnt.Create(apiContext); // ^ Ignore workflow code segment #region Track Workflow this.flow.RecordResponse(createdPayment); #endregion // For more information, please visit [PayPal Developer REST API Reference](https://developer.paypal.com/docs/api/). }
public void CreditCardTokenConstructorTest() { CreditCardToken target = new CreditCardToken(); Assert.IsNotNull(target); }
public void Post_ShouldCreateSubscription() { #region data generation var rand = new Random(); var customer = new Customer { FullName = "Guilherme de castro Titschkoski", EmailAddress = "*****@*****.**" }; var customerRest = new CustomerRestClient(); var postedCustomer = customerRest.Post(customer); var plan = new Plan { PlanCode = "teste-plan-number" + rand.Next(), AccountId = Configuration.GetConfigurationValue("PayU_Account_Id"), Description = "Plano de teste Moblib", PlanInterval = new PlanInterval { Code = "MONTH" }, IntervalCount = 1, MaxPaymentsAllowed = 12, MaxPaymentAttempts = 3, PaymentAttemptsDelay = 1, MaxPendingPayments = 2, TrialDays = 0, AdditionalValues = new List <AdditionalValue> { new AdditionalValue { Name = "PLAN_VALUE", Currency = new Currency { Code = "BRL" }, Value = 1000 } } }; var planRestClient = new PlanRestClient(); var postedPlan = planRestClient.Post(plan); var creditCard = new CreditCardToken { Name = customer.FullName, Document = "41847645844", Customer = new Customer { ContactPhone = "19997323581", CustomerPayUId = postedCustomer.CustomerPayUId }, CreditCardType = new CreditCardType { Code = "MASTERCARD" }, Number = "5555666677778884", ExpirationDate = new DateTime(2021, 11, 01), Country = new Country { Code = "BR" }, Address = new Address { Line1 = "R Jose Paulino, 1875", Line2 = "APTO 41 B", Line3 = null, PostalCode = "13023102", City = "Campinas", State = "SP" } }; var creditCardRestClient = new CreditCardTokenRestClient(); var postedCreditCard = creditCardRestClient.Post(creditCard); #endregion var subscription = new Subscription { Quantity = 12, Installments = 12, TrialDays = 0, Customer = new Customer { CustomerPayUId = postedCustomer.CustomerPayUId, CreditCardTokens = new List <CreditCardToken> { new CreditCardToken { Token = postedCreditCard.Token } } }, Plan = new Plan { PlanCode = postedPlan.PlanCode } }; var sut = new SubscriptionRestClient(); var postedSubscrition = sut.Post(subscription); }
public void ConvertToStringTest() { CreditCardToken token = GetCreditCardToken(); Assert.IsFalse(token.ToString().Length == 0); }
/// <summary> /// Sets the UI settings. /// </summary> /// <param name="creditCardToken">The credit card token.</param> private void SetUISettings(CreditCardToken creditCardToken) { setUpCreditCardDetails.SetUISettings(creditCardToken); }
/// <summary> /// Saves the creadit fatzibra card token. /// </summary> /// <param name="ucCreditCardDetails">The credit card details control.</param> /// <param name="commit">if set to <c>true</c> [commit to database].</param> private void SaveCreaditCardToken(CreditCardDetails ucCreditCardDetails, bool commit) { // If credit card not validated if (Response == null) { ValidateCardDetails(ucCreditCardDetails); } if (Response != null && Response.Successful) { #region Update existing token details if available CreditCardToken creditCardToken = GetCreditCardToken(); if (creditCardToken != null) { creditCardToken.IsActive = false; creditCardToken.LastUpdatedBy = UserID; creditCardToken.LastUpdatedDate = Now; } #endregion Update existing token details if available #region Add New token details CreditCardToken newCreditCardToken = new CreditCardToken(); newCreditCardToken.Token = Utils.EncryptStringAES(Response.Result.ID); newCreditCardToken.CreatedBy = UserID; newCreditCardToken.LastUpdatedBy = UserID; newCreditCardToken.LastUpdatedDate = Now; newCreditCardToken.CreatedDate = Now; newCreditCardToken.IsActive = true; newCreditCardToken.RelatedTableName = RelatedTable; newCreditCardToken.RelatedId = CompanyId; creditCardNumber = ucCreditCardDetails.CreditCardNumber; newCreditCardToken.LastFourDigitsCreditCardNumber = Utils.EncryptStringAES(creditCardNumber.Substring(creditCardNumber.Length - 4)); DataContext.CreditCardTokens.AddObject(newCreditCardToken); #endregion Add New token details #region Check the company status and reactivate it var company = GetBL <CompanyBL>().GetCompany(CompanyId); if (company != null) { CompanyStatusHandler.CompanyWarningInfo warningInfo = CompanyStatusHandler.GetCompanyWarningStatus(CompanyId, company.CompanyStatusCodeId, company.ExpirationDate); if (warningInfo.WarningStatus == CompanyStatusHandler.CompanyWarningStatus.SuspendedForNoPaymentOptions) { CompanyPaymentPackage companyPaymentPackage = GetBL <FinanceBL>().GetCurrentPaymentPackageFortheCompanyIncludingFreeTrial(company.CompanyId); companyPaymentPackage.PaymentMethodCodeId = Support.GetCodeIdByCodeValue("PaymentMethod", "CREDITCARD"); company.CompanyStatusCodeId = Support.GetCodeIdByCodeValue("CompanyStatus", "ACTIVE"); //update if there is summary for the period CompanyPaymentSummary companyPaymentSummary = this.GetBL <FinanceBL>().GetPaymentSummaryToShouldProcess(company.CompanyId); if (companyPaymentSummary != null) { companyPaymentSummary.ShouldProcess = true; } } } #endregion Check the company status and reactivate it if (commit) { DataContext.SaveChanges(); } ucCreditCardDetails.ClearValues(); if (DisplayMode == ViewMode.CompanyBilling) { ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "HideDiv", "HidePaymentSuccessMessage();", true); } popupConfirmPaymentDetails.HidePopup(); } else { StringBuilder sb = new StringBuilder(); if (Response != null && Response.Errors.Count > 0) { sb.Append(string.Join("<br />", Response.Errors)); ucCreditCardDetails.SetNotification(sb.ToString().Length == 0 ? "Failed to set up payment details. Please verify the payment details and retry" : sb.ToString()); } popupConfirmPaymentDetails.ShowPopup(); } }
protected void Page_Load(object sender, EventArgs e) { HttpContext CurrContext = HttpContext.Current; // ###Items // Items within a transaction. Item item = new Item(); item.name = "Item Name"; item.currency = "USD"; item.price = "1"; item.quantity = "5"; item.sku = "sku"; List <Item> itms = new List <Item>(); itms.Add(item); ItemList itemList = new ItemList(); itemList.items = itms; // ###CreditCard // A resource representing a credit card that can be // used to fund a payment. CreditCardToken credCardToken = new CreditCardToken(); credCardToken.credit_card_id = "CARD-5MY32504F4899612AKIHAQHY"; // ###Details // Let's you specify details of a payment amount. Details details = new Details(); details.shipping = "1"; details.subtotal = "5"; details.tax = "1"; // ###Amount // Let's you specify a payment amount. Amount amnt = new Amount(); amnt.currency = "USD"; // Total must be equal to the sum of shipping, tax and subtotal. amnt.total = "7"; amnt.details = details; // ###Transaction // A transaction defines the contract of a // payment - what is the payment for and who // is fulfilling it. Transaction tran = new Transaction(); tran.amount = amnt; tran.description = "This is the payment transaction description."; tran.item_list = itemList; // The Payment creation API requires a list of // Transaction; add the created `Transaction` // to a List List <Transaction> transactions = new List <Transaction>(); transactions.Add(tran); // ###FundingInstrument // A resource representing a Payer's funding instrument. // For stored credit card payments, set the CreditCardToken // field on this object. FundingInstrument fundInstrument = new FundingInstrument(); fundInstrument.credit_card_token = credCardToken; // The Payment creation API requires a list of // FundingInstrument; add the created `FundingInstrument` // to a List List <FundingInstrument> fundingInstrumentList = new List <FundingInstrument>(); fundingInstrumentList.Add(fundInstrument); // ###Payer // A resource representing a Payer that funds a payment // Use the List of `FundingInstrument` and the Payment Method // as 'credit_card' Payer payr = new Payer(); payr.funding_instruments = fundingInstrumentList; payr.payment_method = "credit_card"; // ###Payment // A Payment Resource; create one using // the above types and intent as 'sale' Payment pymnt = new Payment(); pymnt.intent = "sale"; pymnt.payer = payr; pymnt.transactions = transactions; try { // ### Api Context // Pass in a `APIContext` object to authenticate // the call and to send a unique request id // (that ensures idempotency). The SDK generates // a request id if you do not pass one explicitly. // See [Configuration.cs](/Source/Configuration.html) to know more about APIContext.. APIContext apiContext = Configuration.GetAPIContext(); // Create a payment using a valid APIContext Payment createdPayment = pymnt.Create(apiContext); CurrContext.Items.Add("ResponseJson", JObject.Parse(createdPayment.ConvertToJson()).ToString(Formatting.Indented)); } catch (PayPal.Exception.PayPalException ex) { CurrContext.Items.Add("Error", ex.Message); } CurrContext.Items.Add("RequestJson", JObject.Parse(pymnt.ConvertToJson()).ToString(Formatting.Indented)); Server.Transfer("~/Response.aspx"); }