def test_invoice_create(self, users, mock_stripe): """ Successfully create an invoice item. """ user = User.find_by_identity('*****@*****.**') invoice = Invoice() invoice.create(user=user, currency='usd', amount='900', coins=1000, coupon=None, token='cus_000') assert user.coins == 1100
def purchase_coins(): stripe_key = current_app.config.get('STRIPE_PUBLISHABLE_KEY') form = PaymentForm(stripe_key=stripe_key) if form.validate_on_submit(): coin_bundles = current_app.config.get('COIN_BUNDLES') coin_bundles_form = int(request.form.get('coin_bundles')) bundle = next( (item for item in coin_bundles if item['coins'] == coin_bundles_form), None) if bundle is not None: invoice = Invoice() created = invoice.create( user=current_user, currency=current_app.config.get('STRIPE_CURRENCY'), amount=bundle.get('price_in_cents'), coins=coin_bundles_form, coupon=request.form.get('coupon_code'), token=request.form.get('stripe_token')) if created: flash( _('%(amount)s coins have been added to your account.', amount=coin_bundles_form), 'success') else: flash(_('You must enable JavaScript for this request.'), 'warning') return redirect(url_for('bet.place_bet')) return render_template('billing/purchase_coins.html', form=form)