def fees_get(id=None): amount = request.args.get('amount') if amount is None: return "'amount' qs argument required", 400 amount = Decimal(str(amount)) # for now we assume 2 fees: Stripe and Poold fees = fee.get(None, fee_names=['stripe-transaction', 'poold-transaction']) ledger = fee.calculate(fees, amount) ledger = sanitize_json(ledger) return make_response((json.dumps(ledger), 200, [('Content-Type', 'application/json')]))
def fees_get(id=None): amount = request.args.get('amount') if amount is None: return "'amount' qs argument required", 400 amount = Decimal(str(amount)) # for now we assume 2 fees: Stripe and Poold fees = fee.get(None, fee_names=['stripe-transaction', 'poold-transaction']) ledger = fee.calculate(fees, amount) ledger = sanitize_json(ledger) return make_response( (json.dumps(ledger), 200, [('Content-Type', 'application/json')]))
def join_post(id=None): data = request.json c = campaign.get(id) if c is None: return "Unknown campaign.", 404 usr = current_user._get_current_object() token = data['stripeToken'] full_name = data['fullName'] stripe_private_key = app.config.get('STRIPE_SECRET_KEY') try: user.associate_stripe_token(usr, token, stripe_private_key, True) except (PreviousStripeAssociationError, ExternalAPIUsageError): return make_response(('We boned it, please try again later.', 500)) except (ExternalAPIError, ExternalAPIUnavailableError): return make_response((json.dumps( {'error': 'Request failed due to an external dependency.'}), 424)) charge = c.disburse_funds_when == 'immediately' amount = Decimal(data.get('amount')) curr = data.get('currency') curr = currency.get(curr) fees = fee.get(None, fee_names=['stripe-transaction', 'poold-transaction']) if charge: success = charge_user(usr, c, amount, curr, fees, full_name=full_name) if not success: return make_response(('We boned it, please try again later.', 500)) try: campaign.associate_user(c, usr, 'participant', 'participating', pledge=amount) except DuplicateCampaignUserAssociationError: campaign.update_user_association(c, usr, role=None, pledge=amount) ledger = fee.calculate(fees, amount) ledger['date'] = datetime.utcnow().strftime('%m/%d/%Y') send_receipt_email(c, usr, ledger) ledger = sanitize_json(ledger) ledger['date'] = int(time.time()) * 1000 return make_response( (json.dumps(ledger), 201, [('Content-Type', 'application/json')]))
def join_post(id=None): data = request.json c = campaign.get(id) if c is None: return "Unknown campaign.", 404 usr = current_user._get_current_object() token = data['stripeToken'] full_name = data['fullName'] stripe_private_key = app.config.get('STRIPE_SECRET_KEY') try: user.associate_stripe_token(usr, token, stripe_private_key, True) except (PreviousStripeAssociationError, ExternalAPIUsageError): return make_response(('We boned it, please try again later.', 500)) except (ExternalAPIError, ExternalAPIUnavailableError): return make_response((json.dumps({'error': 'Request failed due to an external dependency.'}), 424)) charge = c.disburse_funds_when == 'immediately' amount = Decimal(data.get('amount')) curr = data.get('currency') curr = currency.get(curr) fees = fee.get(None, fee_names=['stripe-transaction', 'poold-transaction']) if charge: success = charge_user(usr, c, amount, curr, fees, full_name=full_name) if not success: return make_response(('We boned it, please try again later.', 500)) try: campaign.associate_user(c, usr, 'participant', 'participating', pledge=amount) except DuplicateCampaignUserAssociationError: campaign.update_user_association(c, usr, role=None, pledge=amount) ledger = fee.calculate(fees, amount) ledger['date'] = datetime.utcnow().strftime('%m/%d/%Y') send_receipt_email(c, usr, ledger) ledger = sanitize_json(ledger) ledger['date'] = int(time.time()) * 1000 return make_response((json.dumps(ledger), 201, [('Content-Type', 'application/json')]))