Esempio n. 1
0
def create_payment(issue_ref, user_name):
    gateway = PaymentGateway.from_string(request.values.get('gateway')) 
    if gateway not in config.PAYMENT_GATEWAYS:
        return jsonify(error="Payment gateway not accepted"), 400

    return_url = request.values.get('return_url')
    
    issue = retrieve_issue(g.project_id, issue_ref)
    user = retrieve_user(g.project_id, user_name)
    
    if issue == None:
        return jsonify(error='Issue not found'), 404

    if user == None:
        return jsonify(error='User not found'), 404
    
    sponsorship = retrieve_sponsorship(issue.issue_id, user.user_id)
    
    if sponsorship.status != SponsorshipStatus.PLEDGED:
        return jsonify(error="You can only create payment for PLEDGED sponsorship"), 403

    payment_gateway = payment_factory.get_payment_gateway(gateway)
    
    payment = payment_gateway.create_payment(g.project_id, sponsorship, return_url)
    update_payment(payment)
    
    return jsonify(message='Payment created')
Esempio n. 2
0
def create_payment(issue_ref, user_name):
    gateway = PaymentGateway.from_string(request.values.get('gateway'))
    if gateway not in config.PAYMENT_GATEWAYS:
        return jsonify(error="Payment gateway not accepted"), 400

    return_url = request.values.get('return_url')

    issue = retrieve_issue(g.project_id, issue_ref)
    user = retrieve_user(g.project_id, user_name)

    if issue == None:
        return jsonify(error='Issue not found'), 404

    if user == None:
        return jsonify(error='User not found'), 404

    sponsorship = retrieve_sponsorship(issue.issue_id, user.user_id)

    if sponsorship.status != SponsorshipStatus.PLEDGED:
        return jsonify(
            error="You can only create payment for PLEDGED sponsorship"), 403

    payment_gateway = payment_factory.get_payment_gateway(gateway)

    payment = payment_gateway.create_payment(g.project_id, sponsorship,
                                             return_url)
    update_payment(payment)

    return jsonify(message='Payment created')
Esempio n. 3
0
def put_payment(issue_ref, user_name):
    status = PaymentStatus.from_string(request.values.get('status'))
    if status != PaymentStatus.CONFIRMED:
        return jsonify(
            error='You can only change the status to CONFIRMED'), 403

    issue = retrieve_issue(g.project_id, issue_ref)
    user = retrieve_user(g.project_id, user_name)

    if issue == None:
        response = jsonify(error='Issue not found'), 404

    elif user == None:
        response = jsonify(error='User not found'), 404

    sponsorship = retrieve_sponsorship(issue.issue_id, user.user_id)

    payment = retrieve_last_payment(sponsorship.sponsorship_id)

    if payment != None:
        if payment.status == status:
            return jsonify(error='Payment already confirmed'), 403

        payment_gateway = payment_factory.get_payment_gateway(payment.gateway)

        approved = payment_gateway.process_payment(g.project_id, sponsorship,
                                                   payment, request.values)
        if not approved:
            return jsonify(error='Payment not confirmed by the gateway'), 403

        payment.status = status
        update_payment(payment)

        sponsorship.status = SponsorshipStatus.CONFIRMED
        update_sponsorship(sponsorship)

        response = jsonify(message='Payment updated')

    else:
        response = jsonify(error='Payment not found'), 404

    return response
Esempio n. 4
0
def put_payment(issue_ref, user_name):
    status = PaymentStatus.from_string(request.values.get('status')) 
    if status != PaymentStatus.CONFIRMED:
        return jsonify(error='You can only change the status to CONFIRMED'), 403
    
    issue = retrieve_issue(g.project_id, issue_ref)
    user = retrieve_user(g.project_id, user_name)
    
    if issue == None:
        response = jsonify(error='Issue not found'), 404

    elif user == None:
        response = jsonify(error='User not found'), 404

    sponsorship = retrieve_sponsorship(issue.issue_id, user.user_id)

    payment = retrieve_last_payment(sponsorship.sponsorship_id)

    if payment != None:
        if payment.status == status:
            return jsonify(error='Payment already confirmed'), 403

        payment_gateway = payment_factory.get_payment_gateway(payment.gateway)

        approved = payment_gateway.process_payment(g.project_id, sponsorship, payment, request.values)
        if not approved:
            return jsonify(error='Payment not confirmed by the gateway'), 403
        
        payment.status = status
        update_payment(payment)
 
        sponsorship.status = SponsorshipStatus.CONFIRMED
        update_sponsorship(sponsorship)
        
        response = jsonify(message='Payment updated')
    
    else:
        response = jsonify(error='Payment not found'), 404
    
    return response