Imports CharterDotCom.CommonEntities.Library.CouponServices
Imports CharterDotCom.CommonEntities.Library
Partial Class TESTHARNESS_TestProviders_TestCouponServices
    Inherits System.Web.UI.Page
    Private _provider As ICouponProvider
    Private Property Provider() As ICouponProvider
        Get
            Return _provider
        End Get
        Set(ByVal value As ICouponProvider)
            _provider = value
        End Set
    End Property
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If IsPostBack Then
            'Dim lProvider As CharterDotCom.CommonEntities.Library.IMemberServicesProvider = CType(Activator.GetObject(GetType(IMemberServicesProvider), CStr(System.Web.HttpContext.Current.Application("RemoteURL_MemberServicesProvider"))), IMemberServicesProvider)
            Dim lProvider As New CouponProvider.ProviderManager
            Me.Provider = lProvider
        End If
    End Sub
   
    Protected Sub btnRedeemCoupon_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnRedeemCoupon.Click
        Try
            Dim objRequest As New CouponRedemptionRequest
            Dim objResult As New CouponRedemptionResponse
            objRequest.AccountId = "1001413459080250"
            objRequest.CouponId = "6ECFX3NRI6"

            objRequest.SourceIPAddress = IIf(Request.ServerVariables("REMOTE_ADDR") Is Nothing, String.Empty, Request.ServerVariables("REMOTE_ADDR"))
            objResult = Me.Provider.RedeemCoupon(objRequest)
            If objResult.Exception Then
                Response.Write("RedeemCoupon Fail, message: " & objResult.ExceptionMessage & "<br>" & objResult.ExceptionStackTrace.ToString())

            Else
                Response.Write("RedeemCoupon has Success, Account ID: " & objRequest.AccountId)

            End If
        Catch ex As Exception
            Response.Write(ex.Message.ToString())
        End Try

    End Sub

    Protected Sub btnCouponStatus_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnCouponStatus.Click
        Try
            Dim objRequest As New GetCouponStatusRequest
            Dim objResult As New GetCouponStatusResponse
            objRequest.accountId = "8351300010013409"
            objRequest.couponID = "36DDOPSA8J"

            objRequest.SourceIPAddress = IIf(Request.ServerVariables("REMOTE_ADDR") Is Nothing, String.Empty, Request.ServerVariables("REMOTE_ADDR"))
            objResult = Me.Provider.GetCouponStatus(objRequest)
            If objResult.Exception Then
                Response.Write("GetCouponStatus Fail, message: " & objResult.ExceptionMessage & "<br>" & objResult.ExceptionStackTrace.ToString())
            Else
                Response.Write("GetCouponStatus has Success, Account ID: " & objRequest.accountId)

            End If
        Catch ex As Exception
            Response.Write(ex.Message.ToString())
        End Try
    End Sub

    Protected Sub btnCustomerRedemptionHistory_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnCustomerRedemptionHistory.Click
        Try
            Dim objRequest As New GetCustomerRedemptionHistoryRequest
            Dim objResult As New GetCustomerRedemptionHistoryResponse
            objRequest.accountId = "1001413459080250"

            objRequest.SourceIPAddress = IIf(Request.ServerVariables("REMOTE_ADDR") Is Nothing, String.Empty, Request.ServerVariables("REMOTE_ADDR"))
            objResult = Me.Provider.GetCustomerRedemptionHistory(objRequest)
            If objResult.Exception Then
                Response.Write("GetCustomerRedemptionHistory Fail, message: " & objResult.ExceptionMessage & "<br>" & objResult.ExceptionStackTrace.ToString())
            Else
                Response.Write("GetCustomerRedemptionHistory has Success, Account ID: " & objRequest.accountId)
            End If
        Catch ex As Exception
            Response.Write(ex.Message.ToString())
        End Try
    End Sub

    Protected Sub btnGiftCardLookup_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnGiftCardLookup.Click

        Try

            Dim request As New GiftCardLookupRequest
            request.AccountId = "8351300010013409"
            request.CouponId = "75F1J2CAVE"

            Dim result As GiftCardLookupResponse
            result = Me.Provider.GiftCardLookup(request)

            If result.Exception = False Then
                Response.Write("Coupon Type: " & result.CouponType)
            Else
                Response.Write("Fail")
            End If

        Catch ex As Exception
            Response.Write(ex.Message.ToString)
        End Try

    End Sub

    Protected Sub btnRedeemGiftCard_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnRedeemGiftCard.Click

        Try

            Dim request As New GiftCardRedemptionRequest
            request.AccountId = "8351300010010413"
            request.CouponId = "7TDJCKZIF9"
            request.Address = New BLAddress
            With request.Address
                .Street1 = "70 BENTON DR"
                .City = "GREENVILLE"
                .State = "SC"
                .Zip = "68104"
            End With

            Dim result As GiftCardRedemptionResponse
            result = Me.Provider.RedeemGiftCard(request)

            If result.Exception = False Then
                Response.Write(result.GiftCardRedemptionResult.ConfirmationNumber)
            Else
                Response.Write(result.GiftCardRedemptionResult.ValidationFailureMessage)
            End If

        Catch ex As Exception
            Response.Write(ex.Message.ToString)
        End Try

    End Sub

End Class

