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
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?
head 422 and return
end
customer = Stripe::Customer.create(
:email => params[:stripeEmail],
:source => params[:stripeToken]
)
# customer = Stripe::Customer.create(
# :email => params[:stripeEmail],
# :source => params[:stripeToken]
# )
charge = Stripe::Charge.create(
:customer => customer.id,
:amount => 1000,
:customer => 'x',
:amount => 1001,
:description => 'Consumer Defender',
:currency => 'aud'
)
BadgeGranter.grant(badge, current_user)
# BadgeGranter.grant(badge, current_user)
render :json => { status: 'OK' }
end

View File

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

View File

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

View File

@ -1,5 +1,21 @@
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', () => {
visit('/users/eviltrout');
@ -21,9 +37,9 @@ test('Payments Page Exists', () => {
test('Payments Page response happens', () => {
visit('/users/eviltrout/payments');
click('.choice-btn');
click('.payment-btn');
andThen(() => {
ok(exists('.choice-response'), 'Response happens');
ok(exists('.payment-response'), 'Response happens');
});
});