Ok, not sure if mongodb can do this, but what I need is for the following JSON to be inserted into my currency DB.
The part we want to update is exchangehistory, we need to keep all the history of the exchange rates for that day. and the next day e.g.
for e.g
{"from":"USD","currentexchange":[{"to":"NZD","rate":"1.3194","updated":"6\/5\/20121:38am"},{"to":"KWD","rate":"0.2807","updated":"6\/5\/20121:38am"},{"to":"GBP","rate":"0.6495","updated":"6\/5\/20121:38am"},{"to":"AUD","rate":"1.0228","updated":"6\/5\/20121:38am"}],"exchangehistory":{"6\/5\/2012":[{"1:38am":[{"to":"NZD","rate":"1.3194","updated":"1:38am"}]},{"1:38am":[{"to":"KWD","rate":"0.2807","updated":"1:38am"}]},{"1:38am":[{"to":"GBP","rate":"0.6495","updated":"1:38am"}]},{"1:38am":[{"to":"AUD","rate":"1.0228","updated":"1:38am"}]}]}}
I would very likely not store this in an array like this. I would create a flat data structure that has:
{
from: "USD",
to: "EUR",
updated: new DateTime("2012-05-04 13:43"),
rate: 1.235,
},
{
from: "USD",
to: "EUR",
updated: new DateTime("2012-05-06 13:43"),
rate: 1.24,
},
{
from: "USD",
to: "AUD",
updated: new DateTime("2012-05-06 13:43"),
rate: 1.43,
}
This is a lot lighter on the database, as documents never grow. And if documents grow they have to be moved. You can also very easily query the current rate:
$collection->find( array( 'from' => 'USD', 'to' => 'EUR' ) )
->sort( 'updated' => -1 )->limit( 1 );
And accessing all historical information:
$collection->find( array( 'from' => 'USD', 'to' => 'EUR' ) )
->sort( 'updated' => -1 )->skip( 1 );
This is not for PHP but it may be useful. you have to make a BSON object from your json string in order to be stored in database.
Creating BSON from JSON
As well you can use MongoDB PHP Driver tutorial and docs. They can be found here : MongoDB PHP Driver Tutorial
Related
As per the stripe documentation here we read all the information and know the ideas about the SCA. But I am not getting any related API documentation. So, I am confusing how to implement in our existing PHP code and what are the parameters we will add. Please find below my example of code:
\Stripe\Stripe::setApiKey(API_KEY_HERE);
$customer = \Stripe\Token::create(
array("card" => array(
"name" => $arg['name'],
"number" => $arg['number'],
"exp_month" => $arg['exp_month'],
"exp_year" => $arg['exp_year'],
"cvc" => $arg['cvc']
))
);
/* some other code here */
$charge = \Stripe\Charge::create(
array(
"amount" => $arg['amount'],
"currency" => "usd",
"description" => "Subscription Charge",
"customer" => $customer->id
)
);
/* some other db related code here */
I have shared the code. Could you please let us know what we need to change for SCA?
I just answered this question where OP did a great job on the question.
Perhaps her code can help you see how you need to implement this using JS in the
front-end and PHP in the backend.
Stripe - Payment Intents (3d secure issue)
I'm trying to integrate PayPal Express Checkout using Braintree SDK.
I can so far charge the Nonce returned from the client and I receive this response. However, I need to take the ID out in order to save it in a table.
My question is how do I parse the id??
Successful {#315
+success: true
-_returnObjectNames: array:1 [
0 => "transaction"
]
#_attributes: []
+"transaction": Transaction {#324
#_attributes: array:63 [
"id" => "xxx"// How do I parse this out?
"status" => "settling"
"type" => "sale"
"currencyIsoCode" => "USD"
"amount" => "6.00"
The variable that holds this JSON is $success. Thus, I tried several things like:
$success->transaction->id
$success->id
If I do $success->success I get true and If I do $success->transaction I get the Transaction object.
Full disclosure: I work at Braintree. If you have any further questions, feel free to contact
support.
If running $success->successreturns True and $success->transaction returns the Transaction object, then you should be able to query the transaction ID using $success->transaction->id, we also demonstrate this in our developer documentation.
$result = $gateway->transaction()->sale([
'amount' => '10.00',
'paymentMethodNonce' => nonceFromTheClient,
'options' => [
'submitForSettlement' => True
]
]);
if ($result->success) {
// See $result->transaction for details
} else {
// Handle errors
}
I would like to update the affects versions field via JIRA REST API. But I'm getting an error:
{"errorMessages":[],"errors":{"versions":"Affects Version/s is required."}}
I have the following code:
public function requestBug($summary, $components, $affectsVersions, $fixVersions, $assignee, $environment, $description)
{
$json = Array ( "fields" => Array (
"project" => Array( "id" => 10051),
"summary" => $summary,
"issuetype" => Array ( "name" => "Bug" ),
"components" =>Array(0 => Array("id" => $components)),
"versions" =>Array(0 =>Array("affectsVersion" => $affectsVersions)),
"versions" =>Array(0 =>Array("fixVersion" =>$fixVersions)),
"assignee" => Array("name" => "$assignee"),
"environment" => "$environment",
"description" =>$description
)
);
return $json;
}
Please assist. I came across this link, but doesnt work for me
I had the same problem and the given answer (even with links provided) did not help me much. I played around with all sorts of variations and finally this piece of JSON worked to change the affected version of an item to "Version 2.0.0":
"versions":
[
{ "Affects Version/s" : "Version 2.0.0"
},
{ "name": "Version 2.0.0"
}
]
Meta data looks like this:
"versions":{"required":true,"schema":
{"type":"array","items":"version","system":"versions"},"name":"Affects Version/s",....
Especially irritating and inconsistent is the fact that the very same field is exported by JIRA as <version>Version 2.0.0</version> in XML and for queries affectedVersion is to be used.
There are a few example of "edit issue" requests here.
You want to send a json that includes something like this:
{
"fields":
{
"versions":["1.0.0","1.1.0"],
"fixVersions":["2.0.0"]
}
}
In your code you use the key "versions" both for "Fix version(s)" and "Affected version(s)", which won't work. Also, you don't have to use additional "affectsVersion" or "fixVersion" keys.
You can also get more info about which fields you can edit and which values they allow using this REST call:
GET /rest/api/2/issue/{issueIdOrKey}/editmeta
Try it out for an issue you want to edit and it should put you on the right track. The output will also show that the "versions" key corresponds to the "Affected version(s)" field.
from jira import JIRA
auth_jira = JIRA('jira.your-oraganizsation.com', auth=('username', 'password'))
new_issue = auth_jira.create_issue(project='project_name', summary='jira_summary', description='jira_description', issuetype={'name': 'Defect'}, fields={'versions': [{'name': '1.0.0'}, {'name': '18.8.0'}] })
I'm trying to get the Podio API (php-library) to return all tasks that have a due date withing a certain range. PodioTask::get_all() works fine, it returns all tasks (limited to 100). Of course that is not very useful so I add attributes as documented:
$tasks = PodioTask::get_all(array(
'org' => [my_organization_id],
'completed' => 'false',
'limit' => 100
)
);
Up until here behavior is still as expected. As soon as I attempt to add the due_date-attribute I get an error message saying Uncaught PodioBadRequestError: "The values are not in the right format" Request URL: http://api.podio.com/task/?org=[my_organization_id]&completed=false&due_date=&limit=100
I try to do it like this, which works fine for the filters on Podio items:
$tasks = PodioTask::get_all(array(
'org' => [my_organization_id],
'completed' => 'false',
'due_date' => array(
'from' => '2d',
'to' => '90d'
),
'limit' => 100
)
);
I tried replacing the from and to dates with absolute ones in the YYYY-MM-DD format (as a string, but also tried a DateTime-object), but I get the same error. I tried removing the array and just setting a single date (as a string and a DateTime object) and none of it works. I keep getting the message that the values are not in the right format. The documentation tells me the due_date-parameter is "The from and to date the task should be due between. For valid options see date filtering under the filter area." If I go there I end up with the documentation for filtering items and I am doing the exact same thing here as for items, which I can filter by date. (https://developers.podio.com/doc/tasks/get-tasks-77949)
It appears like the php-library expects a string, but the API needs the 'from' and 'to' properties.
Anyone got any ideas?
Try this
$attributes = array(
'org' => [my_organization_id],
'completed' => 'false',
'limit' => 100,
'due_date'=> $fromDate.'-'.$toDate
);
$tasks = PodioTask::get_all($attributes);
where $fromDate and $toDate are DateTime Objects.
I have created the following table in DynamoDB:
Field1: messageId / Type: String / Example value: 4873dd28-190a-4363-8299-403c535e160f
Field2: microtime / Type: Number / Example value: 14143960092414
Field3: data / Type: nested JSON-Array / Example value: {"foo":"bar","other":{"nested":1}}
I am performing the following request using PHP SDK for DynamoDB to create an entry
$raw = '{"foo":"bar","other":{"nested":1}}';
$result = $client->putItem(array(
'TableName' => 'requests2',
'Item' => array(
'messageId' => array('S' => '4873dd28-190a-4363-8299-403c535e160f'),
'microtime' => array('N' => microtime(true)*10000),
'data' => array('S' => $raw),
)
));
I want then to query the table and filter using variables within the JSON-array data field. Is my above solution to entering the data the right approach? The JSON-array gets stored as string, as to my understanding. Do we need another datatype? Basically, I can already query the table like below to retrieve messages that were added within the last minute:
$iterator = $client->getIterator('Query', array(
'TableName' => 'requests2',
'KeyConditions' => array(
'messageId' => array(
'AttributeValueList' => array(
array('S' => '4873dd28-190a-4363-8299-403c535e160f')
),
'ComparisonOperator' => 'EQ'
),
'microtime' => array(
'AttributeValueList' => array(
array('N' => strtotime("-1 minutes")*10000)
),
'ComparisonOperator' => 'GT'
)
)
));
foreach ($iterator as $item) {
echo $item['messageId']['S']." ";
}
But how can I modify my request to allow querying by ANY value within the data-field? For example, filter by only those who have [data][other][nested]=1
I've spent the past hours on this issue and I can't get it to work... I am very grateful for any tips, thanks in advance!
I know this was posted in 2014, but I was looking exactly for this answer and so I'd like to share the result in my search to anyone that will land on this question in the future.
Best practice is to store a JSON as a string, but use a Marshaler object to turn the JSON into something that DynamoDB can digest, and that you will be able to query too:
Using marshalJSON method you turn a JSON, as you can see described in this amazon link
For the ones that are looking for a quick example, I add here below the key parts of the procedure:
If you have a JSON like the following
{
"id": "5432c69300594",
"name": {
"first": "Jeremy",
"middle": "C",
"last": "Lindblom"
},
"age": 30,
"phone_numbers": [
{
"type": "mobile",
"number": "5555555555",
"preferred": true
},
{
"type": "home",
"number": "5555555556",
"preferred": false
}
]
}
stored in a string variable $json, you can simply do
use AwsDynamoDbDynamoDbClient;
use AwsDynamoDbMarshaler;
$client = DynamoDbClient::factory(/* your config */);
$marshaler = new Marshaler();
$client->putItem([
'TableName' => 'YourTable',
'Item' => $marshaler->marshalJson($json)
]);
I don't think AWS PHP SDK for DynamoDB has yet implemented the support for JSON based document storage. Their recent notification published on their blog on 8th October 2014, mentions about the support of this new feature only in Java, .NET, Ruby and JS SDK.