Skip to content
This repository has been archived by the owner on Mar 15, 2018. It is now read-only.

Commit

Permalink
Work with the real trans. status API (bug 987758)
Browse files Browse the repository at this point in the history
Things are working! Exciting!
  • Loading branch information
kumar303 committed Jun 3, 2014
1 parent 2f597d7 commit af80a6e
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 22 deletions.
25 changes: 15 additions & 10 deletions lib/fxpay.js
Expand Up @@ -143,18 +143,15 @@
return cb('TRANSACTION_TIMEOUT');
}

// TODO: get or post?
api.post(transStatusPath, null, function(err, data) {
api.get(transStatusPath, function(err, data) {
if (err) {
return cb(err);
}

// TODO: make sure these state values are realistic.
if (data.state === 'COMPLETED') {
// The transaction is complete.
if (data.status === 'complete') {
return cb(null, data);
} else if (data.state === 'PENDING') {
log.debug('Re-trying pending transaction in',
} else if (data.status === 'incomplete') {
log.debug('Re-trying incomplete transaction in',
opt.pollIntervalMs, 'ms');
window.setTimeout(function() {
getTransactionResult(api, transStatusPath, cb, {
Expand All @@ -165,8 +162,8 @@
});
}, opt.pollIntervalMs);
} else {
log.error('transaction state', data.state, 'from',
api.url(transStatusPath), 'was unexpected');
log.error('transaction status', data.status, 'from',
transStatusPath, 'was unexpected');
return cb('INVALID_TRANSACTION_STATE');
}
});
Expand Down Expand Up @@ -199,7 +196,15 @@
var log = this.log;
var api = this;
var url;
if (/^http(s):\/\/.*/.test(path)) {
if (!cb) {
cb = function(err, data) {
if (err) {
throw err;
}
log.info('default callback received data:', data);
};
}
if (/^http(s)?:\/\/.*/.test(path)) {
// Requesting an absolute URL so no need to prefix it.
url = path;
} else {
Expand Down
38 changes: 26 additions & 12 deletions tests/test-fxpay.js
Expand Up @@ -55,7 +55,7 @@ describe('fxpay', function () {
mozPay.returnValues[0].onsuccess();

server.respondWith(
'POST',
'GET',
apiUrl + '/transaction/XYZ',
transactionData());
server.respond();
Expand Down Expand Up @@ -90,9 +90,9 @@ describe('fxpay', function () {

server.autoRespond = true;
server.respondWith(
'POST',
'GET',
/http.*\/transaction\/XYZ/,
transactionData({state: 'PENDING'}));
transactionData({status: 'incomplete'}));
server.respond();
});

Expand Down Expand Up @@ -123,7 +123,7 @@ describe('fxpay', function () {

// Respond to polling the transaction.
server.respondWith(
'POST',
'GET',
/.*\/transaction\/XYZ/,
transactionData());
server.respond();
Expand Down Expand Up @@ -181,9 +181,9 @@ describe('fxpay', function () {

// Respond to polling the transaction.
server.respondWith(
'POST',
'GET',
/http.*\/transaction\/XYZ/,
transactionData({state: 'THIS_IS_NOT_A_VALID_STATE'}));
transactionData({status: 'THIS_IS_NOT_A_VALID_STATE'}));
server.respond();

receiptAdd.onsuccess();
Expand Down Expand Up @@ -297,7 +297,7 @@ describe('fxpay', function () {
mozPay.returnValues[0].onsuccess();

server.respondWith(
'POST',
'GET',
/.*\/transaction\/XYZ/,
transactionData({receipt: receipt}));
server.respond();
Expand Down Expand Up @@ -327,7 +327,7 @@ describe('fxpay', function () {
mozPay.returnValues[0].onsuccess();

server.respondWith(
'POST',
'GET',
/.*\/transaction\/XYZ/,
transactionData());
server.respond();
Expand Down Expand Up @@ -503,8 +503,23 @@ describe('fxpay', function () {
server.respond();
});

it('should request an absolute URL when specified', function (done) {
var absUrl = 'https://somewhere-else.com/some/page';
it('should request an absolute https URL when specified', function (done) {
var absUrl = 'https://secure-site.com/some/page';

server.respondWith('POST', absUrl,
[200, {"Content-Type": "application/json"},
'{"foo":"bar"}']);

api.post(absUrl, null, function(err) {
// If this is not a 404 then we're good.
done(err);
});

server.respond();
});

it('should request an absolute http URL when specified', function (done) {
var absUrl = 'http://insecure-site.com/some/page';

server.respondWith('POST', absUrl,
[200, {"Content-Type": "application/json"},
Expand Down Expand Up @@ -579,8 +594,7 @@ function transactionData(overrides, status) {
// Create a JSON server response to a request for transaction data.
overrides = overrides || {};
var data = {
// TODO: make the state value realistic.
state: 'COMPLETED',
status: 'complete',
// Pretend this is a real Marketplace receipt.
receipt: '<keys>~<receipt>'
};
Expand Down

0 comments on commit af80a6e

Please sign in to comment.