Esempio n. 1
0
        // POST /api/invoices
        public async Task <InvoicePayload> Post([FromBody] InvoicePayload incomingPayload)
        {
            // Validate the bearer token
            string actionPerformer = await TokenValidator.ValidateAuthorizationHeader(Request.Headers.Authorization);

            if (string.IsNullOrEmpty(actionPerformer))
            {
                throw new UnauthorizedAccessException();
            }

            // TODO: A real payment processor should validate that the action performer
            // matches the email address that the invoice was sent to

            // Get the event type
            string eventType = incomingPayload.MethodData[0].Data.Event;

            if (eventType == PayEvent.LoadEntity)
            {
                return(CreateMockLoadEntityResponse(incomingPayload));
            }

            if (eventType == PayEvent.ShippingAddressChange)
            {
                return(CreateMockShippingAddressResponse(incomingPayload));
            }

            if (eventType == PayEvent.ShippingOptionChange)
            {
                return(CreateMockShippingOptionResponse(incomingPayload));
            }

            throw new HttpResponseException(HttpStatusCode.BadRequest);
        }
Esempio n. 2
0
        // POST /api/payments
        public async Task <PaymentCompleteResponse> Post([FromBody] PaymentResponse payment)
        {
            // Validate the bearer token
            string actionPerformer = await TokenValidator.ValidateAuthorizationHeader(Request.Headers.Authorization);

            if (string.IsNullOrEmpty(actionPerformer))
            {
                throw new UnauthorizedAccessException();
            }

            // TODO: A real payment processor should validate that the action performer
            // matches the email address that the invoice was sent to

            // Parse the token
            PaymentToken parsedToken = new PaymentToken(payment.Details.PaymentToken);

            // The sample only supports test tokens
            if (!parsedToken.IsTestToken)
            {
                throw new HttpResponseException(HttpStatusCode.BadRequest);
            }

            // Check the format
            switch (parsedToken.Format.ToLower())
            {
            case "stripe":
                return(CreateMockStripePaymentResponse(parsedToken, payment));

            default:
                throw new HttpResponseException(HttpStatusCode.BadRequest);
            }
        }