Esempio n. 1
0
        public string CreateCustomer(
            string firstName, string middleName, string lastName,
            string birthday, string sex,
            string line1, string line2,
            string city, string state, string zipCode, string countryCode,
            string phone, string email
            )
        {
            var customerData = new
            {
                firstName,
                middleName,
                lastName,
                sex,
                contact = new
                {
                    phone,
                    email
                },
                billingAddress = new
                {
                    line1,
                    line2,
                    city,
                    state,
                    zipCode,
                    countryCode
                },
                metadata = new { }
            };

            if (_repository.Entities.CustomerRecords.Any(customer => customer.email == email))
            {
                return(_repository.Entities.CustomerRecords.Where(customer => customer.email == email).FirstOrDefault().id);
            }

            string jsonInput  = new JavaScriptSerializer().Serialize(customerData);
            string jsonOutput = PayMayaGateway
                                .GetInstance()
                                .SendRequest(_secretKey, _customerCreationUrl, jsonInput);
            string id = CustomerService.GetInstance().GetCustomerId(jsonOutput);

            _repository.Entities.CustomerRecords.Add(new CustomerRecord
            {
                id       = id,
                jsonData = jsonOutput,
                email    = email
            });

            _repository.Entities.SaveChanges();

            return(id);
        }
Esempio n. 2
0
        public string RegisterCard(string customerId,
                                   string cardNumber,
                                   string expirationMonth, string expirationYear,
                                   string cvc)
        {
            var cardData = new
            {
                card = new
                {
                    number   = cardNumber,
                    expMonth = expirationMonth,
                    expYear  = expirationYear,
                    cvc
                }
            };

            string hash = PayMayaGateway
                          .GetInstance()
                          .HashGenerator(cardNumber);

            if (_repository.Entities.CardRecords.Any(card => card.hashNumber == hash))
            {
                return(_repository.Entities.CardRecords.Where(card => card.hashNumber == hash).FirstOrDefault().paymentTokenId);
            }

            string jsonInput  = new JavaScriptSerializer().Serialize(cardData);
            string jsonOutput = PayMayaGateway
                                .GetInstance()
                                .SendRequest(_publicKey, _cardCreationUrl, jsonInput);
            string paymentTokenId = PaymentService.GetInstance().GetPaymentTokenId(jsonOutput);

            _repository.Entities.CardRecords.Add(new CardRecord
            {
                paymentTokenId = paymentTokenId,
                hashNumber     = hash
            });

            try
            {
                _repository.Entities.SaveChanges();
            }
            catch
            {
                throw;
            }

            return(hash);
        }
Esempio n. 3
0
        public string CreatePayment(string customer_id, string cardHash,
                                    decimal amount, string currency
                                    )
        {
            CustomerRecord customerEntry = _repository.Entities.CustomerRecords.Where(customer => customer.id == customer_id).FirstOrDefault();
            CardRecord     cardEntry     = _repository.Entities.CardRecords.Where(card => card.hashNumber == cardHash).FirstOrDefault();
            string         jsonData      = ((customerEntry != null) && (!string.IsNullOrEmpty(customerEntry.jsonData))) ? customerEntry.jsonData : string.Empty;
            JObject        json          = JObject.Parse(jsonData);

            if (!string.IsNullOrEmpty(jsonData))
            {
                json.Property("id").Remove();
                json.Property("sex").Remove();
                json.Property("birthday").Remove();
                json.Property("createdAt").Remove();
                json.Property("updatedAt").Remove();
            }

            var payment = new
            {
                paymentTokenId = (cardEntry != null) ? cardEntry.paymentTokenId : string.Empty,
                totalAmount    = new
                {
                    amount,
                    currency
                },
                buyer = (new JavaScriptSerializer()).Deserialize <object>(json.ToString())
            };

            string jsonInput  = new JavaScriptSerializer().Serialize(payment);
            string jsonOutput = PayMayaGateway
                                .GetInstance()
                                .SendRequest(_secretKey,
                                             _paymentCreationgUrl,
                                             jsonInput);

            string paymentStatus = PaymentService.GetInstance().GetPaymentStatus(jsonOutput);

            return(paymentStatus);
        }