Skip to content

Instantly share code, notes, and snippets.

@reggi
Created August 30, 2012 16:14
Show Gist options
  • Save reggi/3532063 to your computer and use it in GitHub Desktop.
Save reggi/3532063 to your computer and use it in GitHub Desktop.
Mongo
{
"transactions": [
{
"amount": "10.00",
"authorization": null,
"created_at": "2012-08-24T14:02:50-04:00",
"gateway": "bogus",
"id": 999225661,
"kind": "capture",
"order_id": 450789469,
"status": "success",
"test": true,
"receipt": {}
}
]
}
{
"transactions": [
{
"amount": "10.00",
"authorization": null,
"created_at": "2012-08-24T14:02:50-04:00",
"gateway": "bogus",
"id": 999225661,
"kind": "sale",
"order_id": 450789469,
"status": "success",
"test": true,
"receipt": {}
}
]
}
@andredublin
Copy link

You should be able to do this. You must initialize that object property before you can work on it. If the transactions are coming in as an array of objects then you will have to loop through like so

    order.transaction = [];

    for (i = 0; i < order.transactions.length; i++) {
        var value = order.transactions[i];
        if (value.kind === 'sale' || value.kind === 'capture' && value.kind === 'success') {
            order.transaction[i] = {
                "created_at": value.created_at
            }
        }
    }

    console.log(order);
```javascript

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment