示例#1
0
        public CreateTokenResponse Create(Profile profile, CreditCard creditCard, Contact billingContact, string referenceNumber)
        {
            using (log4net.NDC.Push("Create::"))
            {
                var merchantId = GetMerchantId(profile);
                var transactionKey = GetTransactionKey(profile);
                var serviceEndPoint = GetServiceEndPoint(profile);

                var request = CreateRequest();
                request.merchantID = merchantId;
                request.merchantReferenceCode = referenceNumber;
                request.paySubscriptionCreateService = new PaySubscriptionCreateService();
                request.paySubscriptionCreateService.run = "true";

                request.recurringSubscriptionInfo = new RecurringSubscriptionInfo() { frequency = "on-demand" };
                request.card = new Card()
                {
                    cardType = creditCard.CardType,
                    accountNumber = creditCard.CardNumber,
                    expirationMonth = creditCard.ExpirationMonth,
                    expirationYear = creditCard.ExpirationYear
                };
                request.billTo = new BillTo()
                {
                    firstName = billingContact.FirstName,
                    lastName = billingContact.LastName,
                    city = billingContact.City,
                    country = billingContact.Country,
                    email = billingContact.EmailAddress,
                    postalCode = billingContact.PostalCode,
                    state = billingContact.State,
                    street1 = billingContact.StreetLine1,
                };
                request.purchaseTotals = new PurchaseTotals() { currency = "USD" };

                var client = GetCybersourceService(serviceEndPoint, merchantId, transactionKey);

                _logger.Info("\r\nrequest:" + request.ToJSON());
                var reply = client.runTransaction(request);
                _logger.Info("\r\nreply:" + reply.ToJSON());

                var response = new CreateTokenResponse();
                response.Status = true;
                response.ReasonCode = reply.reasonCode;
                if (reply.reasonCode != "100")
                {
                    response.Status = false;
                    response.Message = reply.reasonCode + ". " + Combine(reply.missingField) + Combine(reply.invalidField);
                }
                else
                {
                    response.Token = reply.paySubscriptionCreateReply.subscriptionID;
                }
                return response;
            }
        }
示例#2
0
        public UpdateTokenResponse Update(Profile profile, string token, CreditCard creditCard)
        {
            using (log4net.NDC.Push("Update::"))
            {
                var merchantId = GetMerchantId(profile);
                var transactionKey = GetTransactionKey(profile);
                var serviceEndPoint = GetServiceEndPoint(profile);
                var request = CreateRequest();

                request.merchantID = merchantId;
                request.merchantReferenceCode = DateTime.Now.Ticks.ToString();

                request.paySubscriptionUpdateService = new PaySubscriptionUpdateService();
                request.paySubscriptionUpdateService.run = "true";

                request.card = new Card();
                request.card.expirationMonth = creditCard.ExpirationMonth;
                request.card.expirationYear = creditCard.ExpirationYear;

                request.recurringSubscriptionInfo = new RecurringSubscriptionInfo();
                request.recurringSubscriptionInfo.subscriptionID = token;

                var client = GetCybersourceService(serviceEndPoint, merchantId, transactionKey);

                _logger.Info("\r\nrequest:" + request.ToJSON());
                var reply = client.runTransaction(request);
                _logger.Info("\r\nreply:" + reply.ToJSON());

                var response = new UpdateTokenResponse();
                response.Status = true;
                response.ReasonCode = reply.reasonCode;
                if (reply.reasonCode != "100")
                {
                    response.Status = false;
                    response.Message = reply.reasonCode + ". " + Combine(reply.missingField) + Combine(reply.invalidField);
                }
                return response;
            }
        }