// Create a checkout preference private Preference CreatePreference(Int16 amount, string email) { // Set Checkout Helper CheckoutHelper ch = new CheckoutHelper(); // Create token Token token = ch.CreateAccessToken(Properties.Settings.Default.ClientId, Properties.Settings.Default.ClientSecret); ch.AccessToken = token.AccessToken; // Set item Item item = new Item(); item.CurrencyId = Properties.Settings.Default.CurrencyId; item.Description = Properties.Settings.Default.Description; item.Id = Properties.Settings.Default.ItemId; item.PictureUrl = Properties.Settings.Default.ImageUrl; item.Quantity = 1; item.Title = Properties.Settings.Default.Title; item.UnitPrice = amount; // Set preference Preference preference = new Preference(); preference.BackUrls = new ResponseUrls(); preference.BackUrls.Failure = Properties.Settings.Default.FailureUrl; preference.BackUrls.Pending = Properties.Settings.Default.PendingUrl; preference.BackUrls.Success = Properties.Settings.Default.SuccessUrl; preference.ExternalReference = "my id"; // your id for this transaction preference.Items = new ItemList(); preference.Items.Add(item); preference.Payer = new UserEx(); preference.Payer.Email = email; preference.CustomPaymentChoices = new PaymentChoices(); preference.CustomPaymentChoices.ExcludedTypes = new IdList(); // remove ticket and bank transfer options preference.CustomPaymentChoices.ExcludedTypes.Add("ticket"); preference.CustomPaymentChoices.ExcludedTypes.Add("bank_transfer"); // Create preference preference = ch.CreatePreference(preference); return preference; }
// Create a checkout preference private Preference CreatePreference(Int16 amount, string email) { // Set Checkout Helper CheckoutHelper ch = new CheckoutHelper(); // Create token Token token = AuthHelper.CreateAccessToken(ConfigurationManager.AppSettings["ClientId"], ConfigurationManager.AppSettings["ClientSecret"]); ch.AccessToken = token.AccessToken; // Set item Item item = new Item(); item.CurrencyId = ConfigurationManager.AppSettings["CurrencyId"]; item.Description = ConfigurationManager.AppSettings["Description"]; item.Id = ConfigurationManager.AppSettings["ItemId"]; item.PictureUrl = ConfigurationManager.AppSettings["ImageUrl"]; item.Quantity = 1; item.Title = ConfigurationManager.AppSettings["Title"]; item.UnitPrice = amount; // Set preference Preference preference = new Preference(); preference.BackUrls = new ResponseUrls(); preference.BackUrls.Failure = ConfigurationManager.AppSettings["FailureUrl"]; preference.BackUrls.Pending = ConfigurationManager.AppSettings["PendingUrl"]; preference.BackUrls.Success = ConfigurationManager.AppSettings["SuccessUrl"]; preference.ExternalReference = "my id"; // your id for this transaction preference.Items = new ItemList(); preference.Items.Add(item); preference.Payer = new UserEx(); preference.Payer.Email = email; // Create preference preference = ch.CreatePreference(preference); return preference; }