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