예제 #1
0
        static void CreatePayment()
        {
            Configuration.Secret     = File.ReadAllText("../../../../../SECRET").Trim();
            Configuration.ReceiverId = Int32.Parse(File.ReadAllText("../../../../../RECEIVER_ID").Trim());
            PaymentsApi a = new PaymentsApi();

            try
            {
                PaymentsCreateResponse r = a.PaymentsPost("Pago de Demo", "CLP", 100, notifyUrl: "https://micomercio.com/notify", transactionId: "TX-1234");

                System.Console.WriteLine("PAYMENT_ID: " + r.PaymentId);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
            System.Console.Read();
        }
예제 #2
0
        public async Task <IActionResult> Post([FromBody] Transaccion t)
        {
            if (!ConexionOracle.Activa)
            {
                ConexionOracle.Open();
                if (!ConexionOracle.Activa)
                {
                    return(StatusCode(504, ConexionOracle.NoConResponse));
                }
            }
            try
            {
                Procedimiento p = new Procedimiento(ConexionOracle.Conexion, "SP_ID_PAGO");
                p.Parametros.Add("id_pago", OracleDbType.Int32, ParameterDirection.Output);
                await p.Ejecutar();

                int    idf  = Convert.ToInt32((decimal)(OracleDecimal)(p.Parametros["id_pago"].Value));
                String trId = "TTR" + idf.ToString();
                t.Id_pago = trId;
                t.Fecha   = DateTime.Now;
                if (t.Id_medio == 1)
                {
                    /* ZONA KHIPU */
                    Khipu.Client.Configuration.ReceiverId = Secret.T_RESEIVER_ID;
                    Khipu.Client.Configuration.Secret     = Secret.T_SECRET_KEY;
                    PaymentsApi            pago     = new PaymentsApi();
                    PaymentsCreateResponse response = pago.PaymentsPost(t.Comentario, "CLP", t.Monto, transactionId: trId,
                                                                        returnUrl: ServerURLs.PagarUrl(Accion.repay, t.Id_reserva, trId),
                                                                        cancelUrl: ServerURLs.PagarUrl(Accion.cancel, t.Id_reserva, trId, t.Monto));
                    /**/
                    t.Listo = '1';
                    var r = await cmd.Get <Reserva>(t.Id_reserva);

                    if (r == null)
                    {
                        return(BadRequest(MensajeError.Nuevo("Reserva no existe.")));
                    }
                    r.Valor_pagado += Convert.ToInt32(t.Monto);
                    r.N_pago        = r.N_pago + 1;
                    if (r.Valor_pagado == r.Valor_total)
                    {
                        r.Id_estado = 3;
                    }
                    else if (r.Valor_pagado == Math.Round((double)(r.Valor_total / 2), 0, MidpointRounding.AwayFromZero))
                    {
                        r.Id_estado = 2;
                    }
                    else
                    {
                        r.Id_estado = 1;
                    }
                    await cmd.Update(r);

                    var list = await cmd.Find <Reserva>("Username", t.Username);

                    List <Reserva> rl = new List <Reserva>();
                    foreach (var res in list)
                    {
                        if (res.Id_estado == 3 || res.Id_estado == 4)
                        {
                            rl.Add(res);
                        }
                    }
                    if (rl.Count > 9)
                    {
                        var u = await cmd.Get <Usuario>(t.Username);

                        u.Frecuente = '1';
                        await cmd.Update(u);
                    }
                    if (await cmd.Insert(t, false))
                    {
                        return(Ok(response));
                    }
                }
                else
                {/*
                  * var trs = new Webpay(Transbank.Webpay.Configuration.ForTestingWebpayPlusNormal()).NormalTransaction;
                  * var initResult = trs.initTransaction(t.Monto,trId,"sesion-"+trId, ServerURLs.PagarUrl(Acccion.pay, t.Id_reserva, trId, t.Monto), ServerURLs.PagarUrl(Acccion.commit, t.Id_reserva, trId, t.Monto));
                  * var token = initResult.token;
                  * t.Token = token;
                  * var url = initResult.url;
                  * if (await cmd.Insert(t, false))
                  * {
                  *     return Ok(new { Token = token, Url = url });
                  * }*/
                }
                return(BadRequest());
            }
            catch (Exception e)
            {
                return(StatusCode(500, MensajeError.Nuevo(e.Message)));
            }
        }
예제 #3
0
        public async Task <PaymentsCreateResponse> CreatePaymentRequestAsync(PaymentsCreateRequest contract)
        {
            _log.Info("Creating payment request",
                      new { contract.CustomerId });

            ValidateCreatePaymentRequest(contract);

            LocationInfoResponse locationInfoResponse = null;

            var paymentRequestModel = _mapper.Map <PaymentRequestModel>(contract);

            if (!string.IsNullOrWhiteSpace(contract.ExternalLocationId))
            {
                locationInfoResponse = await _partnerManagementClient.Locations.GetByExternalId2Async(contract.ExternalLocationId);

                if (locationInfoResponse == null)
                {
                    return(new PaymentsCreateResponse {
                        Status = PaymentCreateStatus.LocationNotFound
                    });
                }

                paymentRequestModel.LocationId = locationInfoResponse.Id.ToString();
            }

            var partnerAndLocationStatus = await _partnerAndLocationHelper.ValidatePartnerInfo(contract.PartnerId, locationInfoResponse);

            if (partnerAndLocationStatus != PartnerAndLocationStatus.OK)
            {
                if (partnerAndLocationStatus == PartnerAndLocationStatus.PartnerNotFound)
                {
                    return new PaymentsCreateResponse {
                               Status = PaymentCreateStatus.PartnerNotFound
                    }
                }
                ;
                if (partnerAndLocationStatus == PartnerAndLocationStatus.LocationNotFound)
                {
                    return new PaymentsCreateResponse {
                               Status = PaymentCreateStatus.LocationNotFound
                    }
                }
                ;
            }

            if (contract.PaymentInfo != null)
            {
                var sendMessageResponse =
                    await _messagesService.SendMessageAsync(_mapper.Map <MessagesPostRequest>(contract));

                switch (sendMessageResponse.ErrorCode)
                {
                case MessagesErrorCode.CustomerIsBlocked:
                    return(new PaymentsCreateResponse {
                        Status = PaymentCreateStatus.CustomerIsBlocked
                    });

                case MessagesErrorCode.CustomerNotFound:
                    return(new PaymentsCreateResponse {
                        Status = PaymentCreateStatus.CustomerNotFound
                    });

                case MessagesErrorCode.LocationNotFound:
                    return(new PaymentsCreateResponse {
                        Status = PaymentCreateStatus.LocationNotFound
                    });

                case MessagesErrorCode.PartnerNotFound:
                    return(new PaymentsCreateResponse {
                        Status = PaymentCreateStatus.PartnerNotFound
                    });
                }

                paymentRequestModel.PartnerMessageId = sendMessageResponse.PartnerMessageId;
            }

            var responseModel = await _partnersPaymentsClient.Api.PartnerPaymentAsync(paymentRequestModel);

            var responseContract = new PaymentsCreateResponse()
            {
                PaymentRequestId = responseModel.PaymentRequestId, Status = PaymentCreateStatus.OK
            };

            if (responseModel.Error != PaymentRequestErrorCodes.None)
            {
                _log.Error(null, $"Received error code {responseModel.Error}", responseModel.PaymentRequestId);
                responseContract.Status = _mapper.Map <PaymentCreateStatus>(responseModel.Error);
            }

            //Only save if everything is ok and callback url is provided
            if (responseModel.Error == PaymentRequestErrorCodes.None &&
                !string.IsNullOrEmpty(contract.PaymentProcessedCallbackUrl))
            {
                await _paymentCallbackRepository.InsertAsync(new PaymentProcessedCallbackUrl
                {
                    PaymentRequestId = responseModel.PaymentRequestId,
                    RequestAuthToken = contract.RequestAuthToken,
                    Url = contract.PaymentProcessedCallbackUrl
                });
            }

            return(responseContract);
        }