mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-11-23 23:58:02 -05:00
Add external subs script
This commit is contained in:
parent
7d2c99acd7
commit
52bc660391
2 changed files with 74 additions and 4 deletions
|
@ -3,19 +3,19 @@ c = require './../schemas'
|
|||
PaymentSchema = c.object({title: 'Payment', required: []}, {
|
||||
purchaser: c.objectId(links: [ {rel: 'extra', href: '/db/user/{($)}'} ]) # in case of gifts
|
||||
recipient: c.objectId(links: [ {rel: 'extra', href: '/db/user/{($)}'} ])
|
||||
|
||||
service: { enum: ['stripe', 'ios' ]}
|
||||
|
||||
service: { enum: ['stripe', 'ios', 'invoice']}
|
||||
amount: { type: 'integer', description: 'Payment in cents.' }
|
||||
created: c.date({title: 'Created', readOnly: true})
|
||||
gems: { type: 'integer', description: 'The number of gems acquired.' }
|
||||
productID: { enum: ['gems_5', 'gems_10', 'gems_20']}
|
||||
|
||||
|
||||
ios: c.object({title: 'iOS IAP Data'}, {
|
||||
transactionID: { type: 'string' }
|
||||
rawReceipt: { type: 'string' }
|
||||
localPrice: { type: 'string' }
|
||||
})
|
||||
|
||||
|
||||
stripe: c.object({title: 'Stripe Data'}, {
|
||||
timestamp: { type: 'integer', description: 'Unique identifier provided by the client, to guard against duplicate payments.' }
|
||||
chargeID: { type: 'string' }
|
||||
|
|
70
scripts/mongodb/addExternalSubs.js
Normal file
70
scripts/mongodb/addExternalSubs.js
Normal file
|
@ -0,0 +1,70 @@
|
|||
// Add externally purchased subscriptions
|
||||
|
||||
// Usage:
|
||||
// Edit hard coded data below.
|
||||
// mongo <address>:<port>/<database> <script file> -u <username> -p <password>
|
||||
|
||||
// Skips duplicate payments, but this might be incorrect depending on the scenario
|
||||
|
||||
// TODO: output emails not found
|
||||
|
||||
var emails = ['pam@fred.com', 'Bob@fred.com'];
|
||||
var purchaserID = '54ed0ac0ca7f1c421c025b3d';
|
||||
var endDate = '2015-06-01';
|
||||
var gems = 10500;
|
||||
var amount = 1750;
|
||||
var service = 'invoice';
|
||||
|
||||
emails = emails.map(function(e) { return e.toLowerCase();});
|
||||
|
||||
log("Input Data");
|
||||
log("service\t" + service);
|
||||
log("purchaserID\t" + purchaserID);
|
||||
log("end date\t" + endDate);
|
||||
log("gems\t" + gems);
|
||||
log("amount\t" + amount);
|
||||
log("emails");
|
||||
log(emails);
|
||||
|
||||
// 1. Set free = endDate, updated purchased.gems
|
||||
|
||||
db.users.update(
|
||||
{emailLower: {$in: emails}, "stripe.free": {$ne: endDate}},
|
||||
{
|
||||
$set: {
|
||||
"stripe.free": endDate
|
||||
},
|
||||
$inc: {
|
||||
"purchased.gems": gems
|
||||
}
|
||||
},
|
||||
{
|
||||
multi: true
|
||||
}
|
||||
);
|
||||
|
||||
// 2. create Payment objects
|
||||
|
||||
var cursor = db.users.find({emailLower: {$in: emails}});
|
||||
while (cursor.hasNext()) {
|
||||
var doc = cursor.next();
|
||||
|
||||
var criteria = {
|
||||
purchaser: ObjectId(purchaserID),
|
||||
recipient: doc._id,
|
||||
service: service,
|
||||
gems: gems,
|
||||
amount: amount
|
||||
}
|
||||
if (db.payments.findOne(criteria)) {
|
||||
log("Already have a payment for " + doc.email);
|
||||
}
|
||||
else {
|
||||
db.payments.insert(criteria);
|
||||
log("Added payment for " + doc.email);
|
||||
}
|
||||
}
|
||||
|
||||
function log(str) {
|
||||
print(new Date().toISOString() + " " + str);
|
||||
}
|
Loading…
Reference in a new issue