Пример #1
0
    def delete(self, payment_id):
        """Delete a payment.

        This endpoint will delete a payment based the id specified in the path
        """
        app.logger.info('Request to Delete a payment with id [%s]', payment_id)  # pylint: disable=no-member
        payment = Payment.find(payment_id)
        if payment:
            payment.delete()
        return '', status.HTTP_204_NO_CONTENT
Пример #2
0
def delete_payment(payments_id):
    """
    Delete a payment
    This endpoint will delete a Payment based the id specified in the path
    """
    app.logger.info('Request to delete payment with id: %s', payments_id)
    payment = Payment.find(payments_id)
    if payment:
        payment.delete()
    return make_response('', status.HTTP_204_NO_CONTENT)
Пример #3
0
def get_payments(payments_id):
    """
    Retrieve a single Payment

    This endpoint will return a payment based on it's id
    """
    app.logger.info('Request for payment with id: %s', payments_id)
    payment = Payment.find(payments_id)
    if not payment:
        raise NotFound("Payment with id '{}' was not found.".format(payments_id))
    return make_response(jsonify(payment.serialize()), status.HTTP_200_OK)
Пример #4
0
def toggle_payments_availability(payments_id):
    """
    Toggle payment availability
    This toggles whether or not a payment is currently available
    """
    app.logger.info('Request to toggle payment availability with id: %s', payments_id)
    payment = Payment.find(payments_id)
    if not payment:
        raise NotFound("Payment with id '{}' was not found.".format(payments_id))
    payment.available = not payment.available
    payment.save()
    return make_response(jsonify(payment.serialize()), status.HTTP_200_OK)
Пример #5
0
    def get(self, payment_id):
        """Retrieve a single payment.

        This endpoint will return a payment based on its id.
        """
        app.logger.info(  # pylint: disable=no-member
            "Request to Retrieve a payment with id [%s]", payment_id)
        payment = Payment.find(payment_id)
        if not payment:
            api.abort(status.HTTP_404_NOT_FOUND,
                      "Payment with id '{}' was not found.".format(payment_id))
        return payment.serialize(), status.HTTP_200_OK
Пример #6
0
def update_payments(payments_id):
    """
    Update a Payment

    This endpoint will update a Payment based the body that is posted
    """
    app.logger.info('Request to update payment with id: %s', payments_id)
    check_content_type('application/json')
    payment = Payment.find(payments_id)
    if not payment:
        raise NotFound("Payment with id '{}' was not found.".format(payments_id))
    payment.deserialize(request.get_json())
    payment.id = payments_id
    payment.save()
    return make_response(jsonify(payment.serialize()), status.HTTP_200_OK)
Пример #7
0
    def patch(self, payments_id):
        """Toggle payment availability.

        This toggles whether or not a payment is currently available.
        """
        app.logger.info(  # pylint: disable=no-member
            'Request to toggle payment availability with id: %s', payments_id)
        payment = Payment.find(payments_id)
        if not payment:
            api.abort(
                status.HTTP_404_NOT_FOUND,
                'Payment with id [{}] was not found.'.format(payments_id))
        payment.available = not payment.available
        payment.save()
        return payment.serialize(), status.HTTP_200_OK
Пример #8
0
 def test_find_a_payment(self):
     """ Find a payment by ID"""
     payment = Payment(order_id="1",
                       customer_id="1",
                       available=True,
                       payments_type="credit card")
     payment.save()
     #adding extra row in case the find method return something randomly
     Payment(order_id="2",
             customer_id="2",
             available=False,
             payments_type="paypal").save()
     self.assertTrue(payment is not None)
     self.assertIsNot(payment.id, None)
     new_payment = Payment.find(payment.id)
     self.assertEqual(new_payment.id, payment.id)
Пример #9
0
    def put(self, payment_id):
        """Update a payment.

        This endpoint will update a payment with the body that is posted.
        """
        app.logger.info('Request to Update a payment with id [%s]', payment_id)  # pylint: disable=no-member
        check_content_type('application/json')
        payment = Payment.find(payment_id)
        if not payment:
            api.abort(status.HTTP_404_NOT_FOUND,
                      "Payment with id '{}' was not found.".format(payment_id))
        app.logger.debug('Payload = %s', api.payload)  # pylint: disable=no-member
        data = api.payload
        # Still use jsonschema to validate data.
        jsonschema.validate(data, PAYMENT_SCHEMA)
        payment.deserialize(data)
        payment.id = payment_id
        payment.save()
        return payment.serialize(), status.HTTP_200_OK
Пример #10
0
 def test_find_a_payment(self):
     """ Find a payment by ID """
     saved_payment = Payment(
         order_id="1",
         customer_id="1",
         available=True,
         type="credit card",
         info=self._test_credit_card_info)
     saved_payment.save()
     # adding extra row in case the find method return something randomly
     Payment(
         order_id="2",
         customer_id="2",
         available=False,
         type="paypal",
         info=self._test_paypal_info).save()
     payment = Payment.find(saved_payment.id)
     self.assertIsNot(payment, None)
     self.assertEqual(payment.id, saved_payment.id)
     self.assertEqual(payment.order_id, saved_payment.order_id)
     self.assertEqual(payment.customer_id, saved_payment.customer_id)
     self.assertEqual(payment.available, saved_payment.available)
     self.assertEqual(payment.type, saved_payment.type)
     self.assertEqual(payment.info, saved_payment.info)