Exemplo n.º 1
0
    def get(payment_id):
        try:
            payment = PaymentDAO.query.get(payment_id)
            # Find the existing name request
            nr_model = RequestDAO.query.get(payment.nrId)

            if not nr_model:
                # Should this be a 400 or 404... hmmm
                return jsonify(message='{nr_id} not found'.format(
                    nr_id=nr_model.id)), 400

            receipt_response = get_receipt(payment.payment_token)
            if receipt_response is None:
                return jsonify(message=MSG_NOT_FOUND
                               ), 404  # TODO: What if we have a record?

            response = make_response(receipt_response, 200)
            return response

        except PaymentServiceError as err:
            return handle_exception(err, err.message, 500)
        except SBCPaymentException as err:
            return handle_exception(err, err.message, err.status_code)
        except SBCPaymentError as err:
            return handle_exception(err, err.message, 500)
        except Exception as err:
            return handle_exception(err, err, 500)
Exemplo n.º 2
0
    def post(payment_id):
        try:
            payment = PaymentDAO.query.get(payment_id)
            # Find the existing name request
            nr_model = RequestDAO.query.get(payment.nrId)

            if not nr_model:
                # Should this be a 400 or 404... hmmm
                return jsonify(message='{nr_id} not found'.format(
                    nr_id=nr_model.id)), 400

            receipt_info = get_receipt(payment.payment_token)
            name_choice = RequestDAO.find_name_by_choice(nr_model.id, 1)
            if not name_choice:
                return jsonify(
                    message='Could not find name choice for {nr_id}'.format(
                        nr_id=nr_model.id)), 400

            tz_aware_payment_completion_date = payment.payment_completion_date.replace(
                tzinfo=timezone('UTC'))
            localized_payment_completion_date = tz_aware_payment_completion_date.astimezone(
                timezone('US/Pacific'))
            receipt_req = ReceiptRequest(
                corpName=name_choice.name,
                filingDateTime=localized_payment_completion_date.strftime(
                    '%B %-d, %Y at %-I:%M %P Pacific time'))

            receipt_response = generate_receipt(payment.payment_token,
                                                receipt_req)

            if not receipt_response:
                return jsonify(message=MSG_NOT_FOUND), 404

            return send_file(
                receipt_response,
                as_attachment=True,
                attachment_filename='payment-receipt-{id}.pdf'.format(
                    id=receipt_info.get('receiptNumber')))

        except PaymentServiceError as err:
            return handle_exception(err, err.message, 500)
        except SBCPaymentException as err:
            return handle_exception(err, err.message, err.status_code)
        except SBCPaymentError as err:
            return handle_exception(err, err.message, 500)
        except Exception as err:
            return handle_exception(err, err, 500)
Exemplo n.º 3
0
    def get(payment_id):
        try:
            payment = PaymentDAO.query.get(payment_id)
            # Find the existing name request
            nr_model = RequestDAO.query.get(payment.nrId)

            if not nr_model:
                # Should this be a 400 or 404... hmmm
                return jsonify(message='{nr_id} not found'.format(
                    nr_id=payment.nrId)), 400

            payment_response = get_payment(payment.payment_token)
            # TODO: Make sure we pick the right one... use the first choice
            corp_name = nr_model.names.all()[0].name

            req = PaymentReceiptInput(
                corp_name=corp_name,
                business_number=None,
                recognition_date_time=None,
                filing_identifier=None,
                filing_date_time=payment_response.created_on,
                file_name=None)

            receipt_response = get_receipt(payment.payment_token, req)

            if not receipt_response:
                return jsonify(message=MSG_NOT_FOUND
                               ), 404  # TODO: What if we have a record?

            return send_file(receipt_response,
                             mimetype='application/pdf',
                             as_attachment=True)

        except PaymentServiceError as err:
            return handle_exception(err, err.message, 500)
        except SBCPaymentException as err:
            return handle_exception(err, err.message, err.status_code)
        except SBCPaymentError as err:
            return handle_exception(err, err.message, 500)
        except Exception as err:
            return handle_exception(err, err, 500)
Exemplo n.º 4
0
    def post(payment_identifier):
        try:
            payment_identifier = clean_url_path_param(payment_identifier)

            json_input = request.get_json()
            if not json_input:
                return jsonify(message=MSG_BAD_REQUEST_NO_JSON_BODY), 400

            corp_name = json_input.get('corpName', None)
            business_number = json_input.get('businessNumber', None)
            recognition_date_time = json_input.get('recognitionDateTime', None)
            filing_identifier = json_input.get('filingIdentifier', None)
            filing_date_time = json_input.get('filingDateTime', None)
            file_name = json_input.get('fileName', None)

            req = PaymentReceiptInput(
                corp_name=corp_name,
                business_number=business_number,
                recognition_date_time=recognition_date_time,
                filing_identifier=filing_identifier,
                filing_date_time=filing_date_time,
                file_name=file_name
            )

            receipt = get_receipt(payment_identifier, req)

            if not receipt:
                return jsonify(message=MSG_NOT_FOUND), 404

            return send_file(receipt, mimetype='application/pdf', as_attachment=True)

        except PaymentServiceError as err:
            return handle_exception(err, err.message, 500)
        except SBCPaymentException as err:
            return handle_exception(err, err.message, 500)
        except SBCPaymentError as err:
            return handle_exception(err, err.message, 500)
        except Exception as err:
            return handle_exception(err, err, 500)