public void Should_Refund_Fraudulent_Payment() { CreatePaymentRequest paymentRequest = CreatePaymentRequestBuilder.Create() .StandardListingPayment() .Build(); Payment payment = Payment.Create(paymentRequest, Options); CreateRefundRequest request = new CreateRefundRequest(); request.Locale = Locale.TR.ToString(); request.ConversationId = "123456789"; request.PaymentTransactionId = payment.PaymentItems[0].PaymentTransactionId; request.Price = "0.2"; request.Currency = Currency.TRY.ToString(); request.Ip = "85.34.78.112"; request.Reason = RefundReason.FRAUD.ToString(); request.Description = "stolen card request with 11000 try payment for default sample"; Refund refund = Refund.Create(request, Options); PrintResponse(refund); Assert.AreEqual(Status.SUCCESS.ToString(), refund.Status); Assert.AreEqual(Locale.TR.ToString(), refund.Locale); Assert.AreEqual("123456789", refund.ConversationId); Assert.AreEqual(payment.PaymentId, refund.PaymentId); Assert.AreEqual(payment.PaymentItems[0].PaymentTransactionId, refund.PaymentTransactionId); Assert.AreEqual("0.2", refund.Price.RemoveTrailingZeros()); Assert.NotNull(refund.SystemTime); Assert.Null(refund.ErrorCode); Assert.Null(refund.ErrorMessage); Assert.Null(refund.ErrorGroup); }
public void Should_Refund_With_Reason_And_Description() { CreateRefundRequest request = new CreateRefundRequest(); request.ConversationId = "123456789"; request.Locale = Locale.TR.ToString(); request.PaymentTransactionId = "1"; request.Price = "0.5"; request.Ip = "85.34.78.112"; request.Currency = Currency.TRY.ToString(); request.Reason = RefundReason.OTHER.ToString(); request.Description = "customer requested for default sample"; Refund refund = Refund.Create(request, options); PrintResponse <Refund>(refund); Assert.AreEqual(Status.SUCCESS.ToString(), refund.Status); Assert.AreEqual(Locale.TR.ToString(), refund.Locale); Assert.AreEqual("123456789", refund.ConversationId); Assert.IsNotNull(refund.SystemTime); Assert.IsNull(refund.ErrorCode); Assert.IsNull(refund.ErrorMessage); Assert.IsNull(refund.ErrorGroup); }
/// <summary> /// 本示例介绍如何发起退款,以及如何查询指定 Refund 对象和 Refund 列表 /// </summary> public static Refund Example(string chId) { //退款请求参数,这里只列出必填参数,可选参数请参考 https://pingxx.com/document/api#api-r-new var reParams = new Dictionary <string, object> { // 退款的金额, 单位为对应币种的最小货币单位,例如:人民币为分(如退款金额为 1 元,此处请填 100)。必须小于等于可退款金额,默认为全额退款 { "amount", 100 }, { "description", "Refund Reason" } }; var re = Refund.Create(chId, reParams); Console.WriteLine("****发起交易请求创建 refund 对象****"); Console.WriteLine(re); Console.WriteLine(); Console.WriteLine("****查询指定 refund 对象****"); Console.WriteLine(Refund.Retrieve(chId, re.Id)); Console.WriteLine(); Console.WriteLine("****查询 refund 列表****"); Console.WriteLine(Refund.List(chId, new Dictionary <string, object> { { "limit", 3 } })); Console.WriteLine(); return(re); }
public void RefundThrowOnNullArgs() { Assert.Throws <ArgumentNullException>(delegate { Refund.Create(null); }); Assert.Throws <ArgumentNullException>(delegate { Refund.CreateRaw(null); }); Assert.Throws <ArgumentNullException>(delegate { Refund.List(null); }); Assert.Throws <ArgumentNullException>(delegate { Refund.ListRaw(null); }); Assert.Throws <ArgumentNullException>(delegate { Refund.Retrieve(null, null); }); Assert.Throws <ArgumentNullException>(delegate { Refund.RetrieveRaw(null, null); }); }
public void RefundShouldBeSuccessful() { var purchase = Purchase.Create(120, "M Smith", "5123456789012346", DateTime.Now.AddYears(1), "123", Guid.NewGuid().ToString(), "123.0.0.1"); var refund = Refund.Create(120, purchase.Result.ID, "Refund" + Guid.NewGuid().ToString()); Assert.IsTrue(refund.Successful); Assert.IsTrue(refund.Result.Successful); Assert.IsNotNull(refund.Result.ID); Assert.AreEqual(((Refund)refund.Result).Amount, 120); }
public void RefundThrowOnEmptySecretKey() { Configuration.SecretKey = string.Empty; Assert.Throws <ConfigurationException>(delegate { Refund.Create(PaymentID); }); Assert.Throws <ConfigurationException>(delegate { Refund.CreateRaw(PaymentID); }); Assert.Throws <ConfigurationException>(delegate { Refund.List(PaymentID); }); Assert.Throws <ConfigurationException>(delegate { Refund.ListRaw(PaymentID); }); Assert.Throws <ConfigurationException>(delegate { Refund.Retrieve(PaymentID, RefundID); }); Assert.Throws <ConfigurationException>(delegate { Refund.RetrieveRaw(PaymentID, RefundID); }); }
public async Task <IActionResult> RequestRefund([FromBody] RefundMessageDto refundMessage) { var customer = _usersRepository.GetCustomerById(Guid.Parse(User.Claims.FirstOrDefault(c => c.Type == Helpers.Constants.Strings.JwtClaimIdentifiers.CustomerId)?.Value)); var trip = _tripsRepo.GetTrip(customer.Id, true); if (trip == null) { return(NotFound()); } if (trip.DriverId == null) { ModelState.AddModelError(nameof(Trip), "Driver not assigned"); return(BadRequest(ModelState)); } var user = _usersRepository.GetCustomerById(trip.CustomerId); var refundCreationRes = Refund.Create((ulong)trip.ContractId, new DefaultControllerPattern(), new User() { PrivateKey = user.Identity.PrivateKey }, ModelState); if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var tripHistory = Helpers.ComplexMapping.HistoryFromTrip(trip); await _tripsRepo.AddTripHistory(tripHistory); var refundRequest = Mapper.Map <RefundRequest>(refundMessage); refundRequest.CreationTime = DateTime.UtcNow; refundRequest.CustomerId = customer.Id; refundRequest.TripHistoryId = tripHistory.Id; refundRequest.IdentityId = User.Claims .FirstOrDefault(c => c.Type == Helpers.Constants.Strings.JwtClaimIdentifiers.Id)?.Value; _tripsRepo.AddRefundRequest(refundRequest); _tripsRepo.RemoveTrip(customer.CurrentTrip.CustomerId); //TODO: Admin check refund return(Ok()); }
// GET public ActionResult Create(long amount, string occ, string externalUniqueNumber, string authorizationCode) { try { Refund.Create(amount, occ, externalUniqueNumber, authorizationCode); return(View()); } catch (Exception e) { return(RedirectToAction("Message", "Error", new { error = e.Message })); } }
static void Main(string[] args) { // Setting comerce data Onepay.SharedSecret = "?XW#WOLG##FBAGEAYSNQ5APD#JF@$AYZ"; Onepay.ApiKey = "dKVhq1WGt_XapIYirTXNyUKoWTDFfxaEV63-O5jcsdw"; Onepay.IntegrationType = Transbank.Onepay.Enums.OnepayIntegrationType.Test; // Setting items to the shopping cart ShoppingCart cart = new ShoppingCart(); cart.Add(new Item( description: "Zapatos", quantity: 1, amount: 10000, additionalData: null, expire: 10)); cart.Add(new Item("Pantalon", 1, 5000, null, -1)); // Send transaction to Transbank TransactionCreateResponse response = Transaction.Create(cart); Console.WriteLine(response.ToString()); var bytes = Convert.FromBase64String(response.QrCodeAsBase64); using (var imageFile = new FileStream(@"Qr.jpg", FileMode.Create)) { imageFile.Write(bytes, 0, bytes.Length); imageFile.Flush(); } Console.WriteLine("Pay with the app and then press any key to continue...."); Console.ReadKey(); TransactionCommitResponse commitResponse = Transaction.Commit( response.Occ, response.ExternalUniqueNumber); Console.WriteLine(commitResponse.ToString()); Console.WriteLine("Press any key to Refund Transaction..."); Console.ReadKey(); RefundCreateResponse refundResponse = Refund.Create(commitResponse.Amount, commitResponse.Occ, response.ExternalUniqueNumber, commitResponse.AuthorizationCode); Console.WriteLine(refundResponse.ToString()); Console.WriteLine("Press any key to continue..."); Console.ReadKey(); }
public ActionResult Create(long amount, string occ, string externalUniqueNumber, string authorizationCode) { try { RefundCreateResponse refundResponse = Refund.Create(amount, occ, externalUniqueNumber, authorizationCode); ViewBag.Refund = refundResponse; return(View()); } catch (TransbankException e) { Debug.WriteLine(e.StackTrace); return(RedirectToAction("Error", "Message", new { error = e.Message })); } }
public IActionResult DeleteTripForCustomer() { var customerid = User.Claims.FirstOrDefault(c => c.Type == Helpers.Constants.Strings.JwtClaimIdentifiers.CustomerId)?.Value; if (customerid == null) { return(BadRequest()); } var trip = _tripsRepo.GetTrip(Guid.Parse(customerid)); if (trip == null) { return(NotFound()); } if (trip.DriverId != null) { ModelState.AddModelError(nameof(Trip), "Driver already assigned"); return(BadRequest(ModelState)); } //TODO : refund var customer = _usersRepository.GetCustomerById(Guid.Parse(customerid)); if (customer == null) { return(NotFound()); } var res = Refund.Create((ulong)trip.ContractId, new DefaultControllerPattern(), new User { PrivateKey = customer.Identity.PrivateKey }, ModelState); if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var result = _tripsRepo.RemoveTrip(Guid.Parse(customerid)); if (!result) { return(Conflict()); } return(NoContent()); }
public void TestCreate() { var refdata = DateTimeOffset.Now.Ticks.ToString(); var postData = new List <KeyValuePair <string, string> >(); postData.Add(new KeyValuePair <string, string>("transaction_id", "1")); postData.Add(new KeyValuePair <string, string>("amount", "1.00")); postData.Add(new KeyValuePair <string, string>("reason", refdata)); postData.Add(new KeyValuePair <string, string>("locale", "en")); var res = Refund.Create(postData); Trace.Write(res.ToJson()); Assert.IsTrue(res.Reason == refdata); }
public void RefundThrowOnMissingSecurityProtocol() { Configuration.SecretKey = "mysecretkey"; System.Net.ServicePointManager.SecurityProtocol &= ~SecurityProtocolType.Tls; #if !__MonoCS__ System.Net.ServicePointManager.SecurityProtocol &= ~SecurityProtocolType.Tls11; System.Net.ServicePointManager.SecurityProtocol &= ~SecurityProtocolType.Tls12; #endif Assert.Throws <ConfigurationException>(delegate { Refund.Create(PaymentID); }); Assert.Throws <ConfigurationException>(delegate { Refund.CreateRaw(PaymentID); }); Assert.Throws <ConfigurationException>(delegate { Refund.List(PaymentID); }); Assert.Throws <ConfigurationException>(delegate { Refund.ListRaw(PaymentID); }); Assert.Throws <ConfigurationException>(delegate { Refund.Retrieve(PaymentID, RefundID); }); Assert.Throws <ConfigurationException>(delegate { Refund.RetrieveRaw(PaymentID, RefundID); }); }
public void TestOnepayRefundTransaction() { var amount = 27500; var occ = "1807983490979289"; var externalUniqueNumber = "f506a955-800c-4185-8818-4ef9fca97aae"; var authorizationCode = "623245"; RefundCreateResponse response = Refund.Create(amount, occ, externalUniqueNumber, authorizationCode); Assert.IsNotNull(response); Assert.AreEqual("1807983490979289", response.Occ); Assert.AreEqual("f506a955-800c-4185-8818-4ef9fca97aae", response.ExternalUniqueNumber); Assert.AreEqual("623245", response.ReverseCode); Assert.AreEqual(1532104252, response.IssuedAt); Assert.AreEqual("52NpZBolTEs+ckNOXwGRexDetY9MOaX1QbFYkjPymf4=", response.Signature); }
public void Should_Refund() { CreateRefundRequest request = new CreateRefundRequest(); request.ConversationId = "123456789"; request.Locale = Locale.TR.GetName(); request.PaymentTransactionId = "41"; request.Price = "0.1"; request.Ip = "127.0.0.1"; Refund refund = Refund.Create(request, options); PrintResponse <Refund>(refund); Assert.IsNotNull(refund.SystemTime); Assert.AreEqual(Status.SUCCESS.ToString(), refund.Status); Assert.AreEqual(Locale.TR.GetName(), refund.Locale); Assert.AreEqual("123456789", refund.ConversationId); Assert.AreEqual("41", refund.PaymentTransactionId); }
public void TestOnepayRefundTransaction() { var options = new Options( "mUc0GxYGor6X8u-_oB3e-HWJulRG01WoC96-_tUA3Bg", "P4DCPS55QB2QLT56SQH6#W#LV76IAPYX" ); var amount = 27500; var occ = "1807983490979289"; var externalUniqueNumber = "f506a955-800c-4185-8818-4ef9fca97aae"; var authorizationCode = "623245"; var response = Refund.Create(amount, occ, externalUniqueNumber, authorizationCode, options); Assert.IsNotNull(response); Assert.AreEqual("1807983490979289", response.Occ); Assert.AreEqual("f506a955-800c-4185-8818-4ef9fca97aae", response.ExternalUniqueNumber); Assert.AreEqual("623245", response.ReverseCode); Assert.AreEqual(1532104252, response.IssuedAt); Assert.AreEqual("52NpZBolTEs+ckNOXwGRexDetY9MOaX1QbFYkjPymf4=", response.Signature); }
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."); } }