Skip to content

Commit

Permalink
correct direct payments to use the token ID
Browse files Browse the repository at this point in the history
  • Loading branch information
abianco3 committed Apr 24, 2017
1 parent 8c6bd12 commit 39ea77d
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 23 deletions.
2 changes: 1 addition & 1 deletion client/src/components/userAuctions/ClosedAuction.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const ClosedAuction = ({auction}) => {
}
})
.then(data => {
alert(data);
alert(data.message);
})
.catch(err => {
alert(err);
Expand Down
2 changes: 1 addition & 1 deletion client/src/components/userAuctions/UserAuctions.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class UserAuctions extends Component {
dispatch(userAuctions.fetchingUserAuctions(true));
const headers = new Headers();
headers.append('Content-Type', 'application/json');
headers.append('authorization', `Bearer ${localStorage.getItem('authToken')}`);
headers.append('authorization', `Bearer ${sessionStorage.getItem('authToken')}`);
fetch('/auctions/ongoing', {
headers: headers
})
Expand Down
29 changes: 11 additions & 18 deletions server/controllers/stripe.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,44 +37,37 @@ router.get('/connect/callback', authenticate, (req, res) => {
if (error) {
res.send(error);
}
model.updateStripe(body, req.user.userId)
.then(() => {
model.updateStripe(JSON.parse(body), req.user.userId)
.then((stripeId) => {
return model.updateUserType('artist', req.user.userId);
})
.then(() => {
res.redirect('/');
})
.catch((err) => {
console.log(err.message);
res.status(404).send('Stripe Error - account not connected');
});
});
});

router.post('/charge', authenticate, (req, res) => {
const { token, auction } = req.body;
console.log(req.body);
const userId = req.user.userId;

model.getStripeId(auction.owner_id)
.then((result) => {
console.log(result.stripe_user_id);
stripe.charges.create({
amount: auction.current_bid,
currency: "usd",
source: token,
destination: {
account: result.stripe_user_id,
},
}).then(function(charge) {
currency: 'usd',
source: token.id
}, {
stripe_account: result.stripe_user_id
}).then((charge) => {
// asynchronously called
console.log(charge);
return model.updatePaymentStatus('paid', auction.id)
.then(() => {
res.status(200).json({status: 200, message: 'Payment made succesfully'});
})
.catch((err) => {
res.status(500).send(err);
});
})
.then(() => {
res.status(200).json({status: 200, message: 'Payment made succesfully'});
})
.catch((err) => {
res.status(400).send(err);
Expand Down
6 changes: 3 additions & 3 deletions server/database/queries.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,8 @@ module.exports = {
},

updateStripe(stripeCreds, userId) {
return db.query('UPDATE profiles SET stripe_user_id = $1, refresh_token=$2 \
WHERE user_id=$3', [stripeCreds.stripe_user_id, stripeCreds.refresh_token, userId]);
return db.one('UPDATE profiles SET stripe_user_id = $1, refresh_token=$2 \
WHERE user_id=$3 returning stripe_user_id', [stripeCreds.stripe_user_id, stripeCreds.refresh_token, userId]);
},

getStripeId(userId) {
Expand Down Expand Up @@ -407,7 +407,7 @@ module.exports = {
},

updatePaymentStatus(status, auctionId) {
return db.none('UPDATE closed_auction SET payment_status=$1 WHERE auction_id=$2', [status, auctionId]);
return db.query('UPDATE closed_auctions SET payment_status=$1 WHERE auction_id=$2', [status, auctionId]);
}


Expand Down

0 comments on commit 39ea77d

Please sign in to comment.