sample ajax request

This commit is contained in:
Rimian Perkins 2017-02-15 14:10:52 +11:00
parent 4d2c52e3f2
commit e1778d6bd8
4 changed files with 42 additions and 19 deletions

View File

@ -9,25 +9,25 @@ module DiscoursePayments
end end
def create def create
badge = Badge.find_by_name('Consumer Defender') # badge = Badge.find_by_name('Consumer Defender')
#
# if badge.nil?
# head 422 and return
# end
if badge.nil? # customer = Stripe::Customer.create(
head 422 and return # :email => params[:stripeEmail],
end # :source => params[:stripeToken]
# )
customer = Stripe::Customer.create(
:email => params[:stripeEmail],
:source => params[:stripeToken]
)
charge = Stripe::Charge.create( charge = Stripe::Charge.create(
:customer => customer.id, :customer => 'x',
:amount => 1000, :amount => 1001,
:description => 'Consumer Defender', :description => 'Consumer Defender',
:currency => 'aud' :currency => 'aud'
) )
BadgeGranter.grant(badge, current_user) # BadgeGranter.grant(badge, current_user)
render :json => { status: 'OK' } render :json => { status: 'OK' }
end end

View File

@ -1,10 +1,17 @@
import { ajax } from 'discourse/lib/ajax';
export default Ember.Controller.extend({ export default Ember.Controller.extend({
user: Ember.inject.controller(), user: Ember.inject.controller(),
username: Ember.computed.alias('user.model.username_lower'), username: Ember.computed.alias('user.model.username_lower'),
email: Ember.computed.alias('user.model.email'), email: Ember.computed.alias('user.model.email'),
actions: { actions: {
choiceTest: function() { makePayment: function() {
ajax('/payments', { method: 'POST' }).then(() => {
console.log(this);
});
this.set('saved', true); this.set('saved', true);
} }
} }

View File

@ -2,10 +2,10 @@
{{username}} {{username}}
</div> </div>
<button class='btn btn-primary choice-btn' {{action "choiceTest"}}> <button class='btn btn-primary payment-btn' {{action "makePayment"}}>
click make payment
</button> </button>
{{#if saved}} {{#if saved}}
<div class="choice-response">Response happens</div> <div class="payment-response">Response happens</div>
{{/if}} {{/if}}

View File

@ -1,5 +1,21 @@
import { acceptance } from 'helpers/qunit-helpers'; import { acceptance } from 'helpers/qunit-helpers';
acceptance('Discourse Payments', { loggedIn: true }); acceptance('Discourse Payments', {
loggedIn: true,
setup() {
const response = (object) => {
return [
200,
{"Content-Type": "application/json"},
object
];
};
server.post('/payments', () => {
return response({ });
});
}
}
);
test('Payments Link Exists', () => { test('Payments Link Exists', () => {
visit('/users/eviltrout'); visit('/users/eviltrout');
@ -21,9 +37,9 @@ test('Payments Page Exists', () => {
test('Payments Page response happens', () => { test('Payments Page response happens', () => {
visit('/users/eviltrout/payments'); visit('/users/eviltrout/payments');
click('.choice-btn'); click('.payment-btn');
andThen(() => { andThen(() => {
ok(exists('.choice-response'), 'Response happens'); ok(exists('.payment-response'), 'Response happens');
}); });
}); });