Example #1
0
        private CreatePaymentRequest Prepare3DRequest(ref Options baseHeader)
        {
            try
            {
                ResponsePersonalInformation responseCustomer        = CommonServices.GetCustomer(this.request.CUSTOMER_NUMBER);
                ResponseCustomerAddress     responseCustomerAddress = CommonServices.GetCustomerAddress(this.request.CUSTOMER_NUMBER);
                ResponseBoats responseBoat = CommonServices.GetBoatInfo(this.request.BOAT_ID);

                baseHeader           = new Options();
                baseHeader.ApiKey    = this.request.ApiKey;    // "sandbox-lJr5mWuuVSnwTa5Dt8bE6ohOi6chI463";
                baseHeader.SecretKey = this.request.SecretKey; // "sandbox-yLkfxt1paeOWTZjV7qzn3rwyFPRrC6Cj";
                baseHeader.BaseUrl   = this.request.BaseUrl;   // "https://sandbox-merchant.iyzipay.com";

                CreatePaymentRequest paymentRequest = new CreatePaymentRequest();
                paymentRequest.Locale         = Locale.TR.ToString();
                paymentRequest.ConversationId = this.request.CONVERSATION_ID;
                paymentRequest.Price          = this.request.PRICE;
                paymentRequest.PaidPrice      = this.request.PAID_PRICE;
                paymentRequest.Currency       = Iyzipay.Model.Currency.TRY.ToString();
                paymentRequest.Installment    = 1;
                paymentRequest.BasketId       = GenerateNumberManager.GenerateBasketId();
                paymentRequest.PaymentChannel = PaymentChannel.WEB.ToString();
                paymentRequest.PaymentGroup   = PaymentGroup.PRODUCT.ToString();
                paymentRequest.CallbackUrl    = "https://www.merchant.com/callback";

                paymentRequest.Buyer = new Iyzipay.Model.Buyer()
                {
                    Id                  = this.request.CUSTOMER_NUMBER.ToString(),
                    Name                = responseCustomer.CUSTOMER_NAME,
                    Surname             = responseCustomer.CUSTOMER_SURNAME,
                    GsmNumber           = responseCustomer.PHONE_NUMBER,
                    Email               = responseCustomer.EMAIL,
                    IdentityNumber      = responseCustomer.IDENTIFICATION_ID.ToString(),
                    LastLoginDate       = DateTime.Now.ToShortDateString(),
                    RegistrationDate    = DateTime.Now.ToShortDateString(),
                    RegistrationAddress = responseCustomerAddress.DESCRIPTION,
                    Ip                  = this.request.IP,
                    City                = responseCustomerAddress.CITY,
                    Country             = responseCustomerAddress.COUNTRY,
                    ZipCode             = responseCustomerAddress.ZIPCODE
                };

                paymentRequest.ShippingAddress = new Iyzipay.Model.Address()
                {
                    ContactName = responseCustomer.CUSTOMER_NAME + " " + responseCustomer.CUSTOMER_SURNAME,
                    City        = responseCustomerAddress.CITY,
                    Country     = responseCustomerAddress.COUNTRY,
                    ZipCode     = responseCustomerAddress.ZIPCODE,
                    Description = responseCustomerAddress.DESCRIPTION
                };

                paymentRequest.BillingAddress = new Iyzipay.Model.Address()
                {
                    ContactName = responseCustomer.CUSTOMER_NAME + " " + responseCustomer.CUSTOMER_SURNAME,
                    City        = responseCustomerAddress.CITY,
                    Country     = responseCustomerAddress.COUNTRY,
                    ZipCode     = responseCustomerAddress.ZIPCODE,
                    Description = responseCustomerAddress.DESCRIPTION
                };

                List <BasketItem> basketItems     = new List <BasketItem>();
                BasketItem        firstBasketItem = new BasketItem();
                firstBasketItem.Id        = paymentRequest.BasketId;//Sepet ID si geliştirilecek
                firstBasketItem.Name      = responseBoat.BOAT_NAME;
                firstBasketItem.Category1 = responseBoat.TOUR_TYPE;
                firstBasketItem.Category2 = Enum.GetName(typeof(Enums.TourType), responseBoat.TOUR_TYPE);
                firstBasketItem.ItemType  = BasketItemType.VIRTUAL.ToString();
                firstBasketItem.Price     = responseBoat.TOUR_TYPE == "1" ? responseBoat.PRICE : responseBoat.PRIVATE_PRICE;
                basketItems.Add(firstBasketItem);

                paymentRequest.BasketItems = basketItems;


                return(paymentRequest);
            }
            catch (Exception)
            {
                throw;
            }
        }
Example #2
0
        private CreatePaymentRequest PrepareRequest(ref bool result, ref string errMsg, ref Options baseHeader, ref string errCode)
        {
            try
            {
                Iyzipay.Request.CreatePaymentRequest paymentRequest   = new Iyzipay.Request.CreatePaymentRequest();
                ResponsePersonalInformation          responseCustomer = CommonServices.GetCustomer(this.request.CUSTOMER_NUMBER);
                ResponseCustomerAddress responseCustomerAddress       = CommonServices.GetCustomerAddress(this.request.CUSTOMER_NUMBER);
                ResponseBoats           responseBoat = CommonServices.GetBoatInfo(this.request.BOAT_ID);

                baseHeader           = new Options();
                baseHeader.ApiKey    = this.request.ApiKey;    // "sandbox-lJr5mWuuVSnwTa5Dt8bE6ohOi6chI463";
                baseHeader.SecretKey = this.request.SecretKey; // "sandbox-yLkfxt1paeOWTZjV7qzn3rwyFPRrC6Cj";
                baseHeader.BaseUrl   = this.request.BaseUrl;   // "https://sandbox-merchant.iyzipay.com";

                string cvc = "";
                if (String.IsNullOrEmpty(this.request.PaymentCard.CARD_CVV))
                {
                    cvc = "000";
                }
                else
                {
                    cvc = this.request.PaymentCard.CARD_CVV;
                }

                paymentRequest.PaymentCard = new Iyzipay.Model.PaymentCard()
                {
                    CardHolderName = this.request.PaymentCard.CARD_HOLDER_NAME,
                    CardNumber     = Common.CipherAlgorithm.Decrypt(this.request.PaymentCard.CARD_REF_NUMBER, CipherAlgorithm.password),
                    ExpireMonth    = this.request.PaymentCard.CARD_EXPIRE_MONTH,
                    ExpireYear     = this.request.PaymentCard.CARD_EXPIRE_YEAR,
                    Cvc            = cvc,
                    RegisterCard   = 0//default
                };


                paymentRequest.Buyer = new Iyzipay.Model.Buyer()
                {
                    Id                  = this.request.CUSTOMER_NUMBER.ToString(),
                    Name                = responseCustomer.CUSTOMER_NAME,
                    Surname             = responseCustomer.CUSTOMER_SURNAME,
                    GsmNumber           = responseCustomer.PHONE_NUMBER,
                    Email               = responseCustomer.EMAIL,
                    IdentityNumber      = responseCustomer.IDENTIFICATION_ID.ToString(),
                    LastLoginDate       = DateTime.Now.ToShortDateString(),
                    RegistrationDate    = DateTime.Now.ToShortDateString(),
                    RegistrationAddress = responseCustomerAddress.DESCRIPTION,
                    Ip                  = this.request.IP,
                    City                = responseCustomerAddress.CITY,
                    Country             = responseCustomerAddress.COUNTRY,
                    ZipCode             = responseCustomerAddress.ZIPCODE
                };

                paymentRequest.ShippingAddress = new Iyzipay.Model.Address()
                {
                    ContactName = responseCustomer.CUSTOMER_NAME + " " + responseCustomer.CUSTOMER_SURNAME,
                    City        = responseCustomerAddress.CITY,
                    Country     = responseCustomerAddress.COUNTRY,
                    ZipCode     = responseCustomerAddress.ZIPCODE,
                    Description = responseCustomerAddress.DESCRIPTION
                };

                paymentRequest.BillingAddress = new Iyzipay.Model.Address()
                {
                    ContactName = responseCustomer.CUSTOMER_NAME + " " + responseCustomer.CUSTOMER_SURNAME,
                    City        = responseCustomerAddress.CITY,
                    Country     = responseCustomerAddress.COUNTRY,
                    ZipCode     = responseCustomerAddress.ZIPCODE,
                    Description = responseCustomerAddress.DESCRIPTION
                };

                List <BasketItem> basketItems     = new List <BasketItem>();
                BasketItem        firstBasketItem = new BasketItem();
                firstBasketItem.Id        = GenerateNumberManager.GenerateBasketId();
                firstBasketItem.Name      = responseBoat.BOAT_NAME;
                firstBasketItem.Category1 = responseBoat.TOUR_TYPE;
                firstBasketItem.Category2 = Enum.GetName(typeof(Enums.TourType), responseBoat.TOUR_TYPE);
                firstBasketItem.ItemType  = BasketItemType.VIRTUAL.ToString();
                firstBasketItem.Price     = responseBoat.TOUR_TYPE == "1" ? responseBoat.PRICE : responseBoat.PRIVATE_PRICE;
                basketItems.Add(firstBasketItem);

                paymentRequest.BasketItems = basketItems;

                paymentRequest.Locale         = Locale.TR.ToString();
                paymentRequest.ConversationId = this.request.CONVERSATION_ID;
                paymentRequest.Price          = this.request.PRICE;
                paymentRequest.PaidPrice      = (Convert.ToDecimal(this.request.PAID_PRICE) / 100).ToString().Replace(',', '.');
                paymentRequest.Installment    = 0;
                paymentRequest.BasketId       = firstBasketItem.Id;//Sepet Id'si.
                paymentRequest.PaymentChannel = this.request.PAYMENT_CHANNEL.ToString();
                paymentRequest.PaymentGroup   = PaymentGroup.PRODUCT.ToString();

                switch (this.request.CURRENCY)
                {
                case "949":
                    paymentRequest.Currency = Iyzipay.Model.Currency.TRY.ToString();
                    break;

                case "840":
                    paymentRequest.Currency = Iyzipay.Model.Currency.USD.ToString();
                    break;

                case "978":
                    paymentRequest.Currency = Iyzipay.Model.Currency.EUR.ToString();
                    break;

                case "826":
                    paymentRequest.Currency = Iyzipay.Model.Currency.GBP.ToString();
                    break;

                case "364":
                    paymentRequest.Currency = Iyzipay.Model.Currency.IRR.ToString();
                    break;

                default:
                    paymentRequest.Currency = "";
                    break;
                }

                if (String.IsNullOrEmpty(paymentRequest.Currency))
                {
                    errCode = CommonDefinitions.INTERNAL_SYSTEM_ERROR;
                    errMsg  = CommonDefinitions.CURRENCY_CODE_IS_NOT_VALID;
                    result  = false;
                    log.Info("iyzico Sale Call.. Error on PrepareRequest. Detail : " + errMsg);
                }
                return(paymentRequest);
            }
            catch (Exception ex)
            {
                log.Error("Prepare payment data has occured an ERROR. [Error: " + ex.Message + "]");
                throw ex;
            }
        }