How to get charges(transactions) details in Stripe based on date range - api

I wanted to get a list of charges(Transactions) based on date range I specify, ie all transactions between my specified Start date and End date.
But in CHARGES API, I can not see any Start date nor End Date arguments.
How can I get this?

Had a chat with Stripe staffs through online chat, and found that there is a way to get list of charges based on date range.
Stripe Charges API actually has some argument that are not yet listed in their documentation.
Arguments like created[lte] and created[gte] with Unix timestamp can be used, just like Events API call.
EG: https://api.stripe.com/v1/charges?created[gte]=1362171974&created[lte]=1362517574

Try this one. It's working for me
$pcharges = Charge::all(
array(
'limit' => 100,
'created' => array(
'gte' => strtotime('-15 day'),
'lte' => strtotime('-1 day')
)
)
);
This will return last 15 days data excluding today's transaction. You can set your custom date range as per your requirement.

Here's a Ruby based hack
Stripe.api_key = ENV['STRIPE_SECRET']
stripe_charges = []
first_charge = Stripe::Charge.all(limit: 1).data[0].id
charge_index = first_charge
*a lot of*.times do
new_charges = Stripe::Charge.all(limit: 100, starting_after: charge_index).data
stripe_charges << new_charges
charge_index = new_charges.last.id
stripe_charges.flatten!
end

Was looking in to it today and here is what i found
https://stripe.com/docs/api/curl#list_charges
curl https://api.stripe.com/v1/charges?limit=3 \
-u sk_test_BQokikJOvBiI2HlWgH4olfQ2:
This is stripes curl example there are more examples on their website.
-James Harrington

In case anyone is using Ruby on Rails and is looking for a solution to list out all refunds that's been created after a Unix timestamp, using the created.gte syntax, here's a working example for me that I got from Stripe Support.
Stripe::Refund.list({limit: 100, created: {gte: 1614045880}})
You can change that Unix timestamp to fit your situation.
Resources: Stripe API Reference, List all refunds and Stripe Support

To get particular date data code is like
$mydata= \Stripe\Charge::all(array('limit'=>50,'starting_after'=>null ,"created" => array("gt" => strtotime("2020-02-17"),"lt" => strtotime("2020-02-19"))));
print_r($mydata);
It will give you data of 2020-02-18 with limit 50, If you want more record add last charge id in starting_after parameter

Related

Shopify API - Can't find orders created by another application

I'm trying to find all of my store's orders, and found out that I can only received list of manually created orders, but not orders created by another applications throughout APIs.
Here my current orders list:
And here my code to find all orders
temp = ShopifyAPI::Order.find(:all, :params=>{:status => 'any', :fields => 'name'})
or find single order with order_id
order = ShopifyAPI::Order.find(show_params['order_id'])
The 1st line of code return only 1 order (#1013) created by me
[#<ShopifyAPI::Order:0x0000000c6ae170 #attributes={"name"=>"#1013"}, #prefix_options={}, #persisted=true>]
The 2nd line of code raised error:
#<ActiveResource::ResourceNotFound: Failed. Response code = 404. Response message = Not Found (Not Found).>
Note that all of my other orders except #1013 created by 3rd-application:
What should I do now to find all my orders?
Thank in advance.
P/s: I use 2020-01 api version.
By default, read_orders scope grants you access to get orders created not earlier than 60 days ago.
You have to request read_all_orders scope to be able to fetch all orders now.

Scribe Jobs: how to get the current date and compare it?

Honesty I'm very new in terms of Scribe Jobs, but I have been trying to develop a Job that get the current date and compare it against one field from the source (CRM input Date).
This is the code in the formula editor of the Pre-Operation Step Control:
IF(S146 =TODAY( ), GOTOSTEP ( ),FAILROW( ))
I'm trying to allow the migration only for records inserted today, the rest will just generate error.
Can somebody help me?
Try this:
if( DATEDIFF ("d", GETCURRENTUTCTIME, S146) < 1 )
Here's a great place to look for more information:
http://help.scribesoft.com/scribeonline/en/sol/formulas/datefunctions.htm

Get a products from bigcommerce store based on date?

i would like to get some products in my Bigcommerce store based on date using api. So i have followed the following api code like this. But no luck
$filter = array('date_created' => 'Sat, 25 Jan 2014 16:43:15 +0000');//query filter
$products = Bigcommerce::getProducts($filter);
But in the same way following one is working good.
$filter = array('sku' => 'CST-120');//query filter
$products = Bigcommerce::getProducts($filter);
So please any help me how can i change the date variable would be better

Calculate end date based on # of days and start date

I am working on script where users can make certain type of orders. Now when users make an order they can choose how long they wont it to last in # of days. Once the order is placed I need to approve their order and that approval date is recorded inside my database. Now what I need is to show inside their user panel how much days their package will last since the day of my approval. So for example if I approved their order September 08, 2013 and they choosed for the order to last 7 days, I wont them to see inside they panel for every next day they login how much days they have left, so 7days, 6days, 5days, etc... all the way to "0 Days" when they come to their panel on September 16, 2013.
I have following variables for those two values:
$row_ordersResults['date'] - the date I approved the order
$row_ordersResults['drip_feed'] - # of days they wont for their order to last
I did tried to lots of combinations by myself but I am totally stuck with this and cant make it work.
Thanks for help!
The libraries at momentjs.com is pretty cool. But if you just wanted something simple to calculate the "date difference" between two time values, there is a relatively simple way to do it. I assume you wanted it done in Javascript.
All you need to do is to clear out the hour/minute/second/millisecond fields of the two dates, calculate their differences in days. Put the script below in any web browser and you'll see how it works.
<script>
function foo() {
var d1 = new Date(2013, 8, 12, 13, 40, 1, 333); // any date value, last 4 params can be anything
var d2 = new Date(2013, 9, 3, 11, 42, 32, 533);
d1.setHours(0); d1.setMinutes(0); d1.setSeconds(0); d1.setMilliseconds(0);
d2.setHours(0); d2.setMinutes(0); d2.setSeconds(0); d2.setMilliseconds(0);
daysLeft = (d2.getTime() - d1.getTime())/(24*60*60*1000);
alert('Dear customer, there is(are) ' + daysLeft + ' day(s) left on your order!' );
}
</script>
Show Remaining Days on Order
EDIT: adding PHP version
<?php
$d1 = New DateTime('2013-08-28 06:25:00');
$d2 = new DateTime(); // now
$drip = 55;
$interval = $d2->diff($d1); // time difference
$days_left = $drip - $interval->format('%a'); // in days, subtract from drip
echo "There are $days_left days left\n";
?>
I hope I don't get marked down for not suggesting a specific answer, but time and date calculations are very tedious and JavaScript's Date() provides limited options. So rather than offer some ugly code, I suggest you take a look at moment.js at momentjs.com. Once you attach the script to your pages, you can easily manage all kind of date formats, and set up a function that will allow you to do math on dates and automatically generate your date ranges - it will even let you format them in to user friendly formats like "in 3 days", which I think is what you want. If your app has anything to do with time, and most do, I can't recommend Moment highly enough.

Rails 3 jquery date picker date not saving to database

When I submit my form I can see the date being sent to in the post. However, It doesn't save the date. If I do a date check it says it is not in the proper format. Here is my date picker function, it displays fine:
$j(function(){
$j("#mile_date").datepicker();
});
the $j is because I am using prototype as well so all jquery calls are using the the noconflict variable.
Here is the post:
Parameters: {"utf8"=>"Γ£ô", "authenticity_token"=>"Fj4HW/B4EOan/vcPZLJ75TvWkRH4ZKSFsPLlQLSD0cI=", "mile"=>{"odometer"=>"", "trip"=>"428.2
", "gallons"=>"24.959", "note"=>"", "temperature"=>"", "date"=>"06/22/2011"}, "commit"=>"Create Mile"}
So it sends the date fine but rails doesn't seem to like the format. It inserts a null value into the database. If I submit it with the default datefield with the drop downs it sends this and saves fine:
Parameters: {"utf8"=>"Γ£ô", "authenticity_token"=>"Fj4HW/B4EOan/vcPZLJ75TvWkRH4ZKSFsPLlQLSD0cI=", "mile"=>{"odometer"=>"", "trip"=>"428.2
", "gallons"=>"24.959", "mpg"=>"17.156136063144", "note"=>"", "temperature"=>"", "date(1i)"=>"2011", "date(2i)"=>"6", "date(3i)"=>"22"}, "c
ommit"=>"Create Mile"}
In the insert statement it inserts the date as:'2011-06-22'
Does Rails expect the date in 3 variables to construct the date format correctly? How can I get the datepicker to send the correct date format?
Thank you in advance,
I ran into the same issue. One solution is to simply change the format that the datepicker uses:
// in your javascript...
$j(function(){
$j("#mile_date").datepicker({
dateFormat: "yy-mm-dd"
});
});
Rails seems to be able to handle the yy-mm-dd format - I'm using that and am having no issues saving the date to the database. The only issue here is that some might find the yy-mm-dd format a little less good looking than mm/dd/yyyy...
As noted by #BaronVonBraun above rails doesn't seem to handle that format. Changing it as he suggested worked. However, for those wanting a different format than yy-mm-dd you can use the following. The user sees the format you want while rails gets the format it needs.
$j(function(){
$j("#show_date").datepicker({altField: '#mile_date', altFormat: 'yy-mm-dd'});
});
The show_date is the id of the field they see and the mile_date is a hidden field with the date rails needs.
Here is the documentation.
If anyone is using the jquery_datepicker gem , you'll want to use something similar to the following code in your rails view.
<%= form.hidden_field(:ship_date, :id => "ship_date") %>
<%= datepicker_input(:show_date, item.id, :size => 10, altField: "#ship_date", altFormat: 'yy-mm-dd', :value => item.ship_date.strftime("%m/%d/%Y"))%>
You can also use form.datepicker_input to attach the the date picker directly to the form, but in my use case, I wanted the date picker to reflect the localized date, which Rails would not accept. So I added a hidden form element and set the alternate field to it, works perfectly!
Or try the delocalize gem: https://github.com/clemens/delocalize
j('.jquery-calendar').datepicker().each(function(){
// convert dates from db to US format
var $input = j(this)
var found = $input.val().match(/^(\d{4})-(\d{2})-(\d{2})$/);
if(found){
$input.val(found[2]+'/'+found[3]+'/'+found[1]);
}
});
Kinda of hacky but made a helper the set things straight when I know I am giving the server dates in the mm-dd-yy format
def convert_to_y_m_d(date)
new_date = date.split("-")[2] + "-" + date.split("-")[0] + "-" + date.split("-")[1]
new_date
end