public void Should_Retrieve_Bkm_Result() { RetrieveBkmRequest request = new RetrieveBkmRequest(); request.Locale = Locale.TR.ToString(); request.ConversationId = "123456789"; request.Token = "token"; Bkm bkm = Bkm.Retrieve(request, options); PrintResponse <Bkm>(bkm); Assert.AreEqual(Status.SUCCESS.ToString(), bkm.Status); Assert.AreEqual(Locale.TR.ToString(), bkm.Locale); Assert.AreEqual("123456789", bkm.ConversationId); Assert.IsNotNull(bkm.SystemTime); Assert.IsNull(bkm.ErrorCode); Assert.IsNull(bkm.ErrorMessage); Assert.IsNull(bkm.ErrorGroup); }
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."); } }