agregado procesos y bd clases
This commit is contained in:
196
guia/Extensiones/pagostelematicos.vb
Normal file
196
guia/Extensiones/pagostelematicos.vb
Normal file
@@ -0,0 +1,196 @@
|
||||
Imports System.Text
|
||||
Imports DevExpress.XtraRichEdit.Model
|
||||
|
||||
Partial Public Class pagostelematicos
|
||||
Public ReadOnly Property CodigoRecibo As String
|
||||
Get
|
||||
If Me.idRecibo.HasValue Then
|
||||
Return Me.recibos.CodigoRecibo
|
||||
Else
|
||||
Return ""
|
||||
End If
|
||||
End Get
|
||||
End Property
|
||||
Public Shared Function GeneraPagoTelematico(bd As bdGestionAsegasa.gestionasegasaEntities, OrigenPago As OrigenPagoEnum, Referencia As String, EmailConfirmacionPago As String, Telefono As String, Importe As Double, Optional DNI As String = "", Optional idRecibo As Integer? = Nothing) As pagostelematicos
|
||||
Try
|
||||
If idRecibo.HasValue AndAlso Not bd.recibos.Any(Function(x) x.idRecibo = idRecibo.Value) Then Throw New Exception("No se encuentra el recibo con id: " & idRecibo.Value.ToString)
|
||||
Static r As System.Random = New System.Random()
|
||||
Dim np As New bdGestionAsegasa.pagostelematicos
|
||||
With np
|
||||
.DNI = DNI.Trim().ToUpper()
|
||||
.Referencia = Referencia.Trim().ToUpper()
|
||||
.EmailConfirmacionPago = EmailConfirmacionPago.Trim().ToLower()
|
||||
.Telefono = Telefono
|
||||
.Importe = Math.Round(Importe, 2)
|
||||
.FechaCreacion = Now
|
||||
.idRecibo = idRecibo
|
||||
.OrigenPago = OrigenPago
|
||||
Randomize()
|
||||
.CodigoConfirmacionPago = r.Next(100000000, 999999999).ToString
|
||||
End With
|
||||
bd.pagostelematicos.AddObject(np)
|
||||
bd.SaveChanges()
|
||||
Return np
|
||||
Catch ex As Exception
|
||||
Throw New Exception(ex.Message, ex)
|
||||
End Try
|
||||
End Function
|
||||
End Class
|
||||
Public Enum OrigenPagoEnum
|
||||
PAGO_GENERICO = 0
|
||||
PAGO_RECIBO = 1
|
||||
End Enum
|
||||
Public Class RespuestaRedsysPOST
|
||||
'////////////////////////////
|
||||
'// Atributos de la clase //
|
||||
'/////////////////////////
|
||||
Public Ds_SignatureVersion As String
|
||||
Public Ds_MerchantParameters As String
|
||||
Public Ds_Signature As String
|
||||
Public Confirmacion As ConfirmacionRedsys
|
||||
|
||||
'////////////////////
|
||||
'// Constructores //
|
||||
'//////////////////
|
||||
Public Sub New()
|
||||
MyBase.New()
|
||||
End Sub
|
||||
|
||||
Public Sub New(datosPOST As Specialized.NameValueCollection)
|
||||
'// Esto lo he implementado como un bucle porque no estoy seguro de si los parámetros opcionales llegarán
|
||||
'// vacíos o no llegarán. De este modo, garantizo que no habrá excepciones por exigir la existencia
|
||||
'// de un parámetro que nunca llegue.
|
||||
For Each p In datosPOST
|
||||
If p = "Ds_SignatureVersion" Then Me.Ds_SignatureVersion = datosPOST(p)
|
||||
If p = "Ds_MerchantParameters" Then Me.Ds_MerchantParameters = datosPOST(p)
|
||||
If p = "Ds_Signature" Then Me.Ds_Signature = datosPOST(p)
|
||||
Next
|
||||
|
||||
Dim bDatos As Byte() = Convert.FromBase64String(Ds_MerchantParameters)
|
||||
Dim sDatos As String = Encoding.UTF8.GetString(bDatos)
|
||||
Dim jDatos As ConfirmacionRedsys = Newtonsoft.Json.JsonConvert.DeserializeObject(sDatos, GetType(ConfirmacionRedsys))
|
||||
|
||||
Me.Confirmacion = jDatos
|
||||
End Sub
|
||||
End Class
|
||||
Public Class ConfirmacionRedsys
|
||||
'////////////////////////////
|
||||
'// Atributos de la clase //
|
||||
'/////////////////////////
|
||||
Public Ds_Date As String
|
||||
Public Ds_Hour As String
|
||||
Public Ds_Amount As String
|
||||
Public Ds_Currency As String
|
||||
Public Ds_Order As String
|
||||
Public Ds_MerchantCode As String
|
||||
Public Ds_Terminal As String
|
||||
Public Ds_Response As String
|
||||
Public Ds_MerchantData As String
|
||||
Public Ds_SecurePayment As String
|
||||
Public Ds_TransactionType As String
|
||||
Public Ds_Card_Country As String '// Lista de códigos de país: https://unstats.un.org/unsd/methodology/m49/
|
||||
Public Ds_AuthorisationCode As String
|
||||
Public Ds_ConsumerLanguage As String
|
||||
Public Ds_Card_Type As String
|
||||
Private sSeparadorFecha = "%2F"
|
||||
Private sSeparadorHora = "%3A"
|
||||
|
||||
'//////////////////
|
||||
'// Propiedades //
|
||||
'////////////////
|
||||
Public ReadOnly Property Ds_Date__ComoDate As DateTime
|
||||
Get
|
||||
Dim dd As String = Me.Ds_Date.Split(sSeparadorFecha)(0)
|
||||
Dim mm As String = Me.Ds_Date.Split(sSeparadorFecha)(1).Substring(2, 2)
|
||||
Dim yyyy As String = Me.Ds_Date.Split(sSeparadorFecha)(2).Substring(2, 4)
|
||||
Dim resultado As New Date(yyyy, mm, dd)
|
||||
Return resultado
|
||||
End Get
|
||||
End Property
|
||||
Public ReadOnly Property Ds_Hour__ComoTimeSpan As TimeSpan
|
||||
Get
|
||||
Dim H As String = Me.Ds_Hour.Split(sSeparadorHora)(0)
|
||||
Dim m As String = Me.Ds_Hour.Split(sSeparadorHora)(1).Substring(2, 2)
|
||||
Dim resultado As New TimeSpan(H, m, 0)
|
||||
Return resultado
|
||||
End Get
|
||||
End Property
|
||||
Public ReadOnly Property Ds_Amount__ComoDouble As Double
|
||||
Get
|
||||
Return Me.Ds_Amount / 100.0
|
||||
End Get
|
||||
End Property
|
||||
Public ReadOnly Property Ds_Response__ComoBoolean As Boolean
|
||||
Get
|
||||
Dim resultado As Boolean = False
|
||||
Dim codigoRespuesta As UInteger = UInteger.Parse(Me.Ds_Response)
|
||||
If codigoRespuesta >= 0 AndAlso codigoRespuesta <= 99 Then
|
||||
resultado = True
|
||||
End If
|
||||
Return resultado
|
||||
End Get
|
||||
End Property
|
||||
Public ReadOnly Property Ds_SecurePayment__ComoBoolean As Boolean
|
||||
Get
|
||||
If Me.Ds_SecurePayment = "1" Then
|
||||
Return True
|
||||
Else
|
||||
Return False
|
||||
End If
|
||||
End Get
|
||||
End Property
|
||||
Public ReadOnly Property Ds_Card_Type__ComoEnum As RedsysTipoTarjeta
|
||||
Get
|
||||
Dim resultado As RedsysTipoTarjeta = RedsysTipoTarjeta.NO_PROPORCIONADO
|
||||
If Me.Ds_Card_Type = "C" Then
|
||||
resultado = RedsysTipoTarjeta.CREDITO
|
||||
ElseIf Me.Ds_Card_Type = "D" Then
|
||||
resultado = RedsysTipoTarjeta.DEBITO
|
||||
End If
|
||||
Return resultado
|
||||
End Get
|
||||
End Property
|
||||
Public ReadOnly Property FechaHora As DateTime
|
||||
Get
|
||||
Dim dd As String = Me.Ds_Date.Split(sSeparadorFecha)(0)
|
||||
Dim mm As String = Me.Ds_Date.Split(sSeparadorFecha)(1).Substring(2, 2)
|
||||
Dim yyyy As String = Me.Ds_Date.Split(sSeparadorFecha)(2).Substring(2, 4)
|
||||
Dim H As String = Me.Ds_Hour.Split(sSeparadorHora)(0)
|
||||
Dim m As String = Me.Ds_Hour.Split(sSeparadorHora)(1).Substring(2, 2)
|
||||
Return New DateTime(yyyy, mm, dd, H, m, 0)
|
||||
End Get
|
||||
End Property
|
||||
|
||||
''////////////////////
|
||||
''// Constructores //
|
||||
''//////////////////
|
||||
'Public Sub New()
|
||||
' MyBase.New()
|
||||
'End Sub
|
||||
|
||||
'Public Sub New(datosPOST As Specialized.NameValueCollection)
|
||||
' MyBase.New()
|
||||
' For Each p In datosPOST
|
||||
' If p = "Ds_Date" Then Me.Ds_Date = datosPOST(p)
|
||||
' If p = "Ds_Hour" Then Me.Ds_Hour = datosPOST(p)
|
||||
' If p = "Ds_Amount" Then Me.Ds_Amount = datosPOST(p)
|
||||
' If p = "Ds_Currency" Then Me.Ds_Currency = datosPOST(p)
|
||||
' If p = "Ds_Order" Then Me.Ds_Order = datosPOST(p)
|
||||
' If p = "Ds_MerchantCode" Then Me.Ds_MerchantCode = datosPOST(p)
|
||||
' If p = "Ds_Terminal" Then Me.Ds_Terminal = datosPOST(p)
|
||||
' If p = "Ds_Response" Then Me.Ds_Response = datosPOST(p)
|
||||
' If p = "Ds_MerchantData" Then Me.Ds_MerchantData = datosPOST(p)
|
||||
' If p = "Ds_SecurePayment" Then Me.Ds_SecurePayment = datosPOST(p)
|
||||
' If p = "Ds_TransactionType" Then Me.Ds_TransactionType = datosPOST(p)
|
||||
' If p = "Ds_Card_Country" Then Me.Ds_Card_Country = datosPOST(p)
|
||||
' If p = "Ds_AuthorisationCode" Then Me.Ds_AuthorisationCode = datosPOST(p)
|
||||
' If p = "Ds_ConsumerLanguage" Then Me.Ds_ConsumerLanguage = datosPOST(p)
|
||||
' If p = "Ds_Card_Type" Then Me.Ds_Card_Type = datosPOST(p)
|
||||
' Next
|
||||
'End Sub
|
||||
End Class
|
||||
Public Enum RedsysTipoTarjeta
|
||||
NO_PROPORCIONADO = 0
|
||||
CREDITO = 1
|
||||
DEBITO = 2
|
||||
End Enum
|
||||
Reference in New Issue
Block a user