Exemplo n.º 1
0
        public DeleteTokenResponse Delete(Profile profile, string token)
        {
            using (log4net.NDC.Push("Delete::"))
            {
                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.paySubscriptionDeleteService = new PaySubscriptionDeleteService();
                request.paySubscriptionDeleteService.run = "true";

                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 DeleteTokenResponse();
                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;
            }
        }
Exemplo n.º 2
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;
            }
        }
Exemplo n.º 3
0
        public GetTokenDetailResponse Get(Profile profile, string token)
        {
            using (log4net.NDC.Push("Get::"))
            {
                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.paySubscriptionRetrieveService = new PaySubscriptionRetrieveService();
                request.paySubscriptionRetrieveService.run = "true";

                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 GetTokenDetailResponse();
                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.CreditCard = new CreditCard
                    {
                        CardNumber = reply.paySubscriptionRetrieveReply.cardAccountNumber,
                        CardType = reply.paySubscriptionRetrieveReply.cardType,
                        ExpirationMonth = reply.paySubscriptionRetrieveReply.cardExpirationMonth,
                        ExpirationYear = reply.paySubscriptionRetrieveReply.cardExpirationYear,
                    };
                    response.BillingContact = new Contact
                    {
                        FirstName = reply.paySubscriptionRetrieveReply.firstName,
                        LastName = reply.paySubscriptionRetrieveReply.lastName,
                        City = reply.paySubscriptionRetrieveReply.city,
                        Country = reply.paySubscriptionRetrieveReply.country,
                        CompanyName = reply.paySubscriptionRetrieveReply.companyName,
                        EmailAddress = reply.paySubscriptionRetrieveReply.email,
                        PostalCode = reply.paySubscriptionRetrieveReply.postalCode,
                        State = reply.paySubscriptionRetrieveReply.state,
                        StreetLine1 = reply.paySubscriptionRetrieveReply.street1,
                        StreetLine2 = reply.paySubscriptionRetrieveReply.street2,
                    };
                }
                return response;
            }
        }
Exemplo n.º 4
0
 protected models.TransactionResponse ProcessReply(Profile profile, ReplyMessage reply)
 {
     var response = new models.TransactionResponse();
     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.TransactionId = string.Format("p{0}-{1}", profile.ProfileID, reply.requestID);
     }
     return response;
 }
Exemplo n.º 5
0
 protected string GetTransactionKey(Profile profile)
 {
     return profile.Provider.ProviderSettings.FirstOrDefault(p => p.SettingName == "transaction_key").SettingValue;
 }
Exemplo n.º 6
0
 protected string GetServiceEndPoint(Profile profile)
 {
     return profile.Provider.ProviderSettings.FirstOrDefault(p => p.SettingName == "transactionProcessorUrl").SettingValue;
 }
Exemplo n.º 7
0
 protected string GetMerchantId(Profile profile)
 {
     return profile.Provider.ProviderSettings.FirstOrDefault(p => p.SettingName == "merchant_id").SettingValue;
 }