Ejemplo n.º 1
0
def create():
    token = get_token(request.headers)
    try:
        customer = CustomerCreate.call(token, PAYMENT_PROCESSOR, request.json)
    except InvalidCustomer:
        return jsonify(
            'Customer details are invalid. Check; first_name, last_name, email, company, phone'
        ), HTTPStatus.BAD_REQUEST

    return jsonify(customer.as_dict()), HTTPStatus.CREATED
Ejemplo n.º 2
0
def create():
    customer_token = get_token(request.headers)
    payment_token = get_payment_token(request.headers)
    try:
        payment_method = PaymentMethodCreate.call(PAYMENT_PROCESSOR,
                                                  customer_token,
                                                  payment_token, request.json)
    except (InvalidPaymentMethod, InvalidPaymentProcessorPaymentInformation):
        return jsonify(
            'The payment method details are invalid. Please try new details'
        ), HTTPStatus.BAD_REQUEST

    return jsonify(payment_method.as_dict()), HTTPStatus.CREATED
Ejemplo n.º 3
0
def create():
    customer_token = get_token(request.headers)
    payment_token = get_payment_token(request.headers)
    try:
        sale = SaleCreate.call(PAYMENT_PROCESSOR, customer_token,
                               payment_token, request.json)
    except (InvalidPaymentMethod, InvalidCustomer):
        return jsonify(
            'The customer or/and the payment token are invalid. Please try new tokens.'
        ), HTTPStatus.BAD_REQUEST
    except InvalidSale:
        return jsonify('The camount is not provided. Please try new amount.'
                       ), HTTPStatus.BAD_REQUEST

    return jsonify(sale), HTTPStatus.CREATED
Ejemplo n.º 4
0
    def test_get_token_returns_token_when_token_present(self):
        headers = {'Authorization': 'Bearer sometoken'}

        assert utils.get_token(headers) == 'sometoken'
Ejemplo n.º 5
0
    def test_get_token_returns_none_when_no_token_present(self):
        headers = {}

        assert utils.get_token(headers) is None