private static void CardTest() { var obj = new Card { CardNumber = "5216005329772352", CardExpirationDate = "0822", HolderName = "Jose Silva", Cvv = "544" }; Console.Write("Testing Card"); obj.Create(); Console.WriteLine(obj.Id != null ? " - Success" : " - Fail"); }
public static Subscription SubsCreate() { //any plan var plan = Plan.GetAllPlans().First(); //fake credit card var card = new Card { CardNumber = "5367624274512386", //master card HolderName = "Jose Silva", Cvv = "547", CardExpirationDate = "0822" }; //gererating a hash to be used for subscription var hash = card.GenerateHash(); //client data var customer = new Customer { Email = "*****@*****.**", Name = "José Silva", Phones = new List<Phone> { new Phone { Ddd = "11", Ddi = "+55", Number = "987456321" } } }; var obj = new Subscription { PlanId = plan.Id, Customer = customer, CardHash = hash }; obj.Create(); return obj; }
private static void CreditCardTransaction() { var obj = new Card { CardNumber = "5216005329772352", CardExpirationDate = "0822", HolderName = "Jose Silva", Cvv = "544" }; obj.Create(); var t = new Transaction { Amount = 9999, //R$ 99,99 CardId = obj.Id, SoftDescriptor = "", //Invoice description Capture = false, //Just authorize Metadata = new Metadata { IdData = 1, NomeData = "Sale 1" }, //Just to tag Customer = new Customer { Addresses = new List<Address> { new Address { City = "São Paulo", Complementary = "AP3", Neighborhood = "Bela Vista", Country = "BR", State = "SP", Street = "Av Paulista", StreetNumber = "1000", Zipcode = "01318002" } }, BornAt = new DateTime(1980, 1, 1), DocumentNumber = "02460608322", DocumentType = eCustomerDocumentType.cpf, Email = "*****@*****.**", Gender = eGender.male, Name = "Emanuel Lima", Phones = new List<Phone>{ new Phone { Ddd = "11", Ddi = "55", Number = "984628620" } } } }; t.Create(); }
public static string GenerateHash(Card card) { //getting a public key from pagarme. this key is valid for 5 minutes and works only once. var key = Transaction.GetCardHashKey(); var args = new List<Tuple<string, string>>(); args.Add(new Tuple<string, string>("card_number", card.CardNumber)); args.Add(new Tuple<string, string>("card_expiration_date", card.CardExpirationDate)); args.Add(new Tuple<string, string>("card_holder_name", card.HolderName)); args.Add(new Tuple<string, string>("card_cvv", card.Cvv)); var encrypted = EncryptRsa(key.PublicKey, Encoding.UTF8.GetBytes(BuildQueryString(args))); return key.Id + "_" + Convert.ToBase64String(encrypted); }