post data from stripe form
This commit is contained in:
parent
c23833830a
commit
d6a00ae888
|
@ -1,5 +1,9 @@
|
|||
require_dependency 'discourse'
|
||||
|
||||
module DiscoursePayments
|
||||
class ChargesController < ActionController::Base
|
||||
include CurrentUser
|
||||
|
||||
skip_before_filter :verify_authenticity_token, only: [:create]
|
||||
|
||||
def create
|
||||
|
@ -10,13 +14,13 @@ module DiscoursePayments
|
|||
# end
|
||||
|
||||
customer = Stripe::Customer.create(
|
||||
:email => 'joe@example.com',
|
||||
:email => current_user.email,
|
||||
:source => params[:stripeToken]
|
||||
)
|
||||
|
||||
charge = Stripe::Charge.create(
|
||||
:customer => customer.id,
|
||||
:amount => 1001,
|
||||
:amount => params[:amount],
|
||||
:description => 'Consumer Defender',
|
||||
:currency => 'aud'
|
||||
)
|
||||
|
|
|
@ -1,12 +1,15 @@
|
|||
import { ajax } from 'discourse/lib/ajax';
|
||||
|
||||
export default Ember.Component.extend({
|
||||
stripe: Stripe('pk_test_b8RmhzlL8QPizJRqOrKF3JEV'),
|
||||
|
||||
card: function() {
|
||||
var elements = this.get('stripe').elements();
|
||||
return elements.create('card', { hidePostalCode: true });
|
||||
}.property('stripe'),
|
||||
|
||||
didInsertElement() {
|
||||
this.get('card').mount('#stripe-card');
|
||||
this.get('card').mount('#card-element');
|
||||
},
|
||||
|
||||
actions: {
|
||||
|
@ -16,12 +19,14 @@ export default Ember.Component.extend({
|
|||
console.log('error yo');
|
||||
}
|
||||
else {
|
||||
var form = document.getElementById('stripe-card');
|
||||
var hiddenInput = document.createElement('input');
|
||||
// hiddenInput.setAttribute('type', 'hidden');
|
||||
hiddenInput.setAttribute('name', 'stripeToken');
|
||||
hiddenInput.setAttribute('value', result.token.id);
|
||||
form.appendChild(hiddenInput);
|
||||
var data = {
|
||||
stripeToken: result.token.id,
|
||||
amount: 1234
|
||||
};
|
||||
|
||||
ajax('/charges', { data: data, method: 'post' }).then(data => {
|
||||
console.log(data);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
<div id="stripe-card"></div>
|
||||
<form id="payment-form">
|
||||
<div>
|
||||
<label for="card-element">Credit or debit card</label>
|
||||
<div id="card-element"></div>
|
||||
</div>
|
||||
|
||||
<button class='btn btn-primary payment-btn' {{action "submitStripeCard"}}>
|
||||
make payment
|
||||
</button>
|
||||
<button {{action "submitStripeCard"}}>Submit Payment</button>
|
||||
</form>
|
||||
|
|
Loading…
Reference in New Issue