public void Should_Initialize_Bkm()
        {
            CreateBkmInitializeRequest request = CreateBkmInitializeRequestBuilder.Create()
                                                 .Price("1")
                                                 .CallbackUrl("https://www.merchant.com/callback")
                                                 .Build();

            BkmInitialize bkmInitialize = BkmInitialize.Create(request, Options);

            PrintResponse(request);

            Assert.NotNull(bkmInitialize.HtmlContent);
            Assert.NotNull(bkmInitialize.Token);
            Assert.True(bkmInitialize.HtmlContent.Contains(bkmInitialize.Token));
        }
Exemplo n.º 2
0
        public void Should_Initialize_Bkm()
        {
            CreateBkmInitializeRequest request = new CreateBkmInitializeRequest();

            request.Locale         = Locale.TR.ToString();
            request.ConversationId = "123456789";
            request.Price          = "1";
            request.BasketId       = "B67832";
            request.PaymentGroup   = PaymentGroup.PRODUCT.ToString();
            request.CallbackUrl    = "https://www.merchant.com/callback";

            Buyer buyer = new Buyer();

            buyer.Id                  = "BY789";
            buyer.Name                = "John";
            buyer.Surname             = "Doe";
            buyer.GsmNumber           = "+905350000000";
            buyer.Email               = "*****@*****.**";
            buyer.IdentityNumber      = "74300864791";
            buyer.LastLoginDate       = "2015-10-05 12:43:35";
            buyer.RegistrationDate    = "2013-04-21 15:12:09";
            buyer.RegistrationAddress = "Nidakule Göztepe, Merdivenköy Mah. Bora Sok. No:1";
            buyer.Ip                  = "85.34.78.112";
            buyer.City                = "Istanbul";
            buyer.Country             = "Turkey";
            buyer.ZipCode             = "34732";
            request.Buyer             = buyer;

            Address shippingAddress = new Address();

            shippingAddress.ContactName = "Jane Doe";
            shippingAddress.City        = "Istanbul";
            shippingAddress.Country     = "Turkey";
            shippingAddress.Description = "Nidakule Göztepe, Merdivenköy Mah. Bora Sok. No:1";
            shippingAddress.ZipCode     = "34742";
            request.ShippingAddress     = shippingAddress;

            Address billingAddress = new Address();

            billingAddress.ContactName = "Jane Doe";
            billingAddress.City        = "Istanbul";
            billingAddress.Country     = "Turkey";
            billingAddress.Description = "Nidakule Göztepe, Merdivenköy Mah. Bora Sok. No:1";
            billingAddress.ZipCode     = "34742";
            request.BillingAddress     = billingAddress;

            List <BasketItem> basketItems     = new List <BasketItem>();
            BasketItem        firstBasketItem = new BasketItem();

            firstBasketItem.Id        = "BI101";
            firstBasketItem.Name      = "Binocular";
            firstBasketItem.Category1 = "Collectibles";
            firstBasketItem.Category2 = "Accessories";
            firstBasketItem.ItemType  = BasketItemType.PHYSICAL.ToString();
            firstBasketItem.Price     = "0.3";
            basketItems.Add(firstBasketItem);

            BasketItem secondBasketItem = new BasketItem();

            secondBasketItem.Id        = "BI102";
            secondBasketItem.Name      = "Game code";
            secondBasketItem.Category1 = "Game";
            secondBasketItem.Category2 = "Online Game Items";
            secondBasketItem.ItemType  = BasketItemType.VIRTUAL.ToString();
            secondBasketItem.Price     = "0.5";
            basketItems.Add(secondBasketItem);

            BasketItem thirdBasketItem = new BasketItem();

            thirdBasketItem.Id        = "BI103";
            thirdBasketItem.Name      = "Usb";
            thirdBasketItem.Category1 = "Electronics";
            thirdBasketItem.Category2 = "Usb / Cable";
            thirdBasketItem.ItemType  = BasketItemType.PHYSICAL.ToString();
            thirdBasketItem.Price     = "0.2";
            basketItems.Add(thirdBasketItem);
            request.BasketItems = basketItems;

            BkmInitialize bkmInitialize = BkmInitialize.Create(request, options);

            PrintResponse <BkmInitialize>(bkmInitialize);

            Assert.AreEqual(Status.SUCCESS.ToString(), bkmInitialize.Status);
            Assert.AreEqual(Locale.TR.ToString(), bkmInitialize.Locale);
            Assert.AreEqual("123456789", bkmInitialize.ConversationId);
            Assert.IsNotNull(bkmInitialize.SystemTime);
            Assert.IsNull(bkmInitialize.ErrorCode);
            Assert.IsNull(bkmInitialize.ErrorMessage);
            Assert.IsNull(bkmInitialize.ErrorGroup);
            Assert.IsNotNull(bkmInitialize.HtmlContent);
        }
Exemplo n.º 3
0
        public override void DoOperation()
        {
            try
            {
                //Validate Reques Header / Constants
                this.baseResponseMessage = ValidateInput();
                if (!this.baseResponseMessage.header.IsSuccess)
                {
                    throw new Exception(this.baseResponseMessage.header.ResponseMessage);
                }

                Options baseHeader = null;
                string  errMsg     = "";
                string  errCode    = "";
                bool    result     = true;

                //Operation
                switch (this.request.Header.OperationTypes)
                {
                case (int)OperationType.OperationTypes.ADD:
                    #region PAYMENT

                    //Create payments
                    Iyzipay.Request.CreatePaymentRequest paymentRequest = PrepareRequest(ref result, ref errMsg, ref baseHeader, ref errCode);
                    Payment payment = Payment.Create(paymentRequest, baseHeader);

                    RetrievePaymentRequest request = new RetrievePaymentRequest();
                    request.Locale                = Locale.TR.ToString();
                    request.ConversationId        = payment.ConversationId;
                    request.PaymentId             = payment.PaymentId;
                    request.PaymentConversationId = payment.ConversationId;

                    //check payments
                    Payment Checkpayments = Payment.Retrieve(request, baseHeader);
                    if (Checkpayments.Status == Status.FAILURE.ToString())
                    {
                        throw new Exception("Odeme basarısız");
                    }

                    bool checkvalue = false;
                    //add transaction
                    CommonServices.AddTransaction(this.request, ref checkvalue);
                    //response
                    this.response = new ResponsePayment
                    {
                        CALLBACK_URL     = paymentRequest.CallbackUrl,
                        CARD_HOLDER_NAME = paymentRequest.PaymentCard.CardHolderName,
                        CARD_REF_NUMBER  = paymentRequest.PaymentCard.CardNumber,
                        CONVERSATION_ID  = payment.ConversationId,
                        CURRENCY         = payment.Currency,
                        CUSTOMER_NUMBER  = Convert.ToInt64(paymentRequest.Buyer.Id),
                        IP              = paymentRequest.Buyer.Ip,
                        PAID_PRICE      = payment.PaidPrice,
                        PRICE           = payment.Price,
                        PAYMENT_CHANNEL = paymentRequest.PaymentChannel,
                        PAYMENT_ID      = Checkpayments.PaymentId,
                        header          = new ResponseHeader
                        {
                            IsSuccess       = checkvalue == false ? false : true,
                            ResponseCode    = checkvalue == false ? CommonDefinitions.INTERNAL_TRANSACTION_ERROR : CommonDefinitions.SUCCESS,
                            ResponseMessage = checkvalue == false ? CommonDefinitions.ERROR_MESSAGE : CommonDefinitions.SUCCESS_MESSAGE
                        }
                    };

                    #endregion
                    break;

                case (int)OperationType.OperationTypes.DELETE:
                    #region REFUND

                    //Create ReFund
                    FillOptionHeader(ref baseHeader);
                    CreateRefundRequest refundRequest = new CreateRefundRequest();
                    refundRequest.ConversationId       = this.request.CONVERSATION_ID;
                    refundRequest.Locale               = Locale.TR.ToString();
                    refundRequest.PaymentTransactionId = this.request.PAYMENT_ID;
                    refundRequest.Price    = this.request.PRICE;
                    refundRequest.Ip       = this.request.IP;
                    refundRequest.Currency = this.request.CURRENCY;

                    //check refund
                    Refund refund = Refund.Create(refundRequest, baseHeader);
                    if (refund.Status == Status.FAILURE.ToString())
                    {
                        throw new Exception(" Geri ödeme basarısız");
                    }

                    //Transaction
                    checkvalue = false;
                    //add transaction
                    CommonServices.AddTransaction(this.request, ref checkvalue);

                    //response
                    this.response = new ResponsePayment
                    {
                        CALLBACK_URL     = this.request.CALLBACK_URL,
                        CARD_HOLDER_NAME = this.request.CARD_HOLDER_NAME,
                        CARD_REF_NUMBER  = this.request.CARD_REF_NUMBER,
                        CONVERSATION_ID  = refundRequest.ConversationId,
                        CURRENCY         = refundRequest.Currency,
                        CUSTOMER_NUMBER  = this.request.CUSTOMER_NUMBER,
                        IP              = refundRequest.Ip,
                        PAID_PRICE      = refundRequest.Price,
                        PRICE           = refundRequest.Price,
                        PAYMENT_CHANNEL = this.request.PAYMENT_CHANNEL,
                        PAYMENT_ID      = refundRequest.PaymentTransactionId,
                        header          = new ResponseHeader
                        {
                            IsSuccess       = checkvalue == false ? false : true,
                            ResponseCode    = checkvalue == false ? CommonDefinitions.INTERNAL_TRANSACTION_ERROR : CommonDefinitions.SUCCESS,
                            ResponseMessage = checkvalue == false ? CommonDefinitions.ERROR_MESSAGE : CommonDefinitions.SUCCESS_MESSAGE
                        }
                    };

                    #endregion
                    break;

                case (int)OperationType.OperationTypes.UPDATE:
                    #region BKM PAYMENT

                    CreateBkmInitializeRequest requestBKM = PrepareBkmRequest(ref baseHeader);
                    BkmInitialize bkmInitialize           = BkmInitialize.Create(requestBKM, baseHeader);

                    RetrieveBkmRequest retrieveBKM = new RetrieveBkmRequest();
                    retrieveBKM.Locale         = Locale.TR.ToString();
                    retrieveBKM.ConversationId = "123456789";
                    retrieveBKM.Token          = "token";

                    Bkm bkm = Bkm.Retrieve(retrieveBKM, baseHeader);
                    if (bkm.Status == Status.FAILURE.ToString())
                    {
                        throw new Exception("Odeme basarısız");
                    }

                    //Transaction
                    checkvalue = false;
                    //add transaction
                    CommonServices.AddTransaction(this.request, ref checkvalue);
                    //response
                    this.response = new ResponsePayment
                    {
                        CALLBACK_URL     = requestBKM.CallbackUrl,
                        CARD_HOLDER_NAME = "",
                        CARD_REF_NUMBER  = "",
                        CONVERSATION_ID  = requestBKM.ConversationId,
                        CURRENCY         = "",
                        CUSTOMER_NUMBER  = Convert.ToInt64(requestBKM.Buyer.Id),
                        IP              = requestBKM.Buyer.Ip,
                        PAID_PRICE      = requestBKM.Price,
                        PRICE           = requestBKM.Price,
                        PAYMENT_CHANNEL = requestBKM.PaymentSource,
                        PAYMENT_ID      = requestBKM.BasketId,
                        header          = new ResponseHeader
                        {
                            IsSuccess       = checkvalue == false ? false : true,
                            ResponseCode    = checkvalue == false ? CommonDefinitions.INTERNAL_TRANSACTION_ERROR : CommonDefinitions.SUCCESS,
                            ResponseMessage = checkvalue == false ? CommonDefinitions.ERROR_MESSAGE : CommonDefinitions.SUCCESS_MESSAGE
                        }
                    };
                    #endregion
                    break;

                case (int)OperationType.OperationTypes.GET:
                    #region 3D PAYMENT
                    //Initialize 3D Payment
                    Iyzipay.Request.CreatePaymentRequest payment3DRequest = Prepare3DRequest(ref baseHeader);
                    ThreedsInitialize threedsInitialize = ThreedsInitialize.Create(payment3DRequest, baseHeader);
                    if (threedsInitialize.Status == Status.FAILURE.ToString())
                    {
                        throw new Exception("Odeme basarısız");
                    }
                    //Create 3D Payment
                    CreateThreedsPaymentRequest create3Drequestpayment = new CreateThreedsPaymentRequest();
                    create3Drequestpayment.Locale           = Locale.TR.ToString();
                    create3Drequestpayment.ConversationId   = payment3DRequest.ConversationId;
                    create3Drequestpayment.PaymentId        = this.request.PAYMENT_ID;
                    create3Drequestpayment.ConversationData = "conversation data";    // ?????

                    ThreedsPayment threedsPayment = ThreedsPayment.Create(create3Drequestpayment, baseHeader);
                    if (threedsPayment.Status == Status.FAILURE.ToString())
                    {
                        throw new Exception("Odeme basarısız");
                    }

                    //Transaction
                    checkvalue = false;
                    //add transaction
                    CommonServices.AddTransaction(this.request, ref checkvalue);
                    //response
                    this.response = new ResponsePayment
                    {
                        CALLBACK_URL     = payment3DRequest.CallbackUrl,
                        CARD_HOLDER_NAME = payment3DRequest.PaymentCard.CardHolderName,
                        CARD_REF_NUMBER  = payment3DRequest.PaymentCard.CardNumber,
                        CONVERSATION_ID  = payment3DRequest.ConversationId,
                        CURRENCY         = payment3DRequest.Currency,
                        CUSTOMER_NUMBER  = Convert.ToInt64(payment3DRequest.Buyer.Id),
                        IP              = payment3DRequest.Buyer.Ip,
                        PAID_PRICE      = payment3DRequest.PaidPrice,
                        PRICE           = payment3DRequest.Price,
                        PAYMENT_CHANNEL = payment3DRequest.PaymentChannel,
                        PAYMENT_ID      = create3Drequestpayment.PaymentId,
                        header          = new ResponseHeader
                        {
                            IsSuccess       = checkvalue == false ? false : true,
                            ResponseCode    = checkvalue == false ? CommonDefinitions.INTERNAL_TRANSACTION_ERROR : CommonDefinitions.SUCCESS,
                            ResponseMessage = checkvalue == false ? CommonDefinitions.ERROR_MESSAGE : CommonDefinitions.SUCCESS_MESSAGE
                        }
                    };

                    #endregion
                    break;

                default:
                    break;
                }
            }
            catch (Exception ex)
            {
                log.Error("Payment Operation has an ERROR: [ERROR : " + ex.Message + "]");
                throw new Exception("Ödeme sirasinda hata oluştu.");
            }
        }