square connect v2 api does not charge cents - square-connect

square connect api is not charging cents. Example, if a client makes a purchase online for $17.25, my billing software shows paid for $17.25 but when I get my square report, it only collected or charged $17.00. So I'm short .25 cents.
My process-card.php file has this;
# Monetary amounts are specified in the smallest unit of the applicable currency.
# This amount is in cents. It's also hard-coded for $1.00, which isn't very useful.
"amount_money" => array (
"amount" => (int)$_POST['amount'] *100,
"currency" => "CAD"
then for testing purpose, I changed the *100 to *111, figuring that it will charge the cents, but this time instead of collecting $17.25 from the invoice, square report showed, received $18.87.
any help would be great.
thank-you

You are type casting your $_POST['amount']as an integer, which would remove anything after the decimal point.
Try removing the (int)

Related

Without proration enabled, any changes made to a customer’s subscription mid-cycle goes into effect immediately

During the implementation of recurring payments using Braintree I encountered a problem.
In documentation I can read: “Without proration enabled, any changes made to a customer’s subscription mid-cycle will go into effect at the beginning of the next cycle.” (https://articles.braintreepayments.com/guides/recurring-billing/recurring-advanced-settings#proration)
But if I edit the subscription to a lower dollar amount in the middle of a billing cycle (without proration on downgrades enabled) e.g. from $100 to $80 and then I edit the subscription to a higher dollar amount (with proration on upgrades enabled) e.g. to $90, the gateway will immediately charge me some amount.
In this situation, I would expect that gateway will not generate any transaction, because downgrade should be effective at the beginning of the next cycle and new subscription price ($90) is lower than initial subscription price (100$).
How can I then reach scenario when transaction on proration upgrade will be generated only if new subscription price is higher than maximum subscription price at the current billing cycle?
I'm a developer at Braintree.
If you kept proration on for both price decreases and increases, in the example you give you would see a credit applied to the subscription balance for the decrease, and then a charge applied against the balance for the increase. If the charge exceeds the subscription balance credit, then your customer would be charged.
A subscription will not be charged in the middle of a billing cycle unless you choose to prorate charges. You could create the scenario you want with logic similar to below. Code snippets are in Ruby since you didn't specify what client library you were using.
First look up the subscription you want to update and find the start date of the current billing period:
subscription = Braintree::Subscription.find("subscription_id")
billing_period_start_date = Date.parse(subscription.billing_period_start_date) # convert String to Date
Then iterate over the status_history events of the subscription, and update the billing_period_max_price if the history event took place after the beginning of this billing cycle and the billing_period_max_price is greater than the previous one:
billing_period_max_price = 0.0
subscription.status_history.each do |history_event|
event_date = Date.parse(history_event.timestamp.strftime('%Y/%m/%d')) # convert Time to Date
event_price = history_event.price.to_f
if event_date >= billing_period_start_date && billing_period_max_price < event_price
billing_period_max_price = event_price
end
end
Finally, if the billing_period_max_price is less than what you want to change the subscription price to, prorate the charges:
Subscription.update(
"subscription_id",
:price => "yourHigherPrice",
:options => { :prorate_charges => true }
)
If you have additional questions, feel free to reach out to Braintree support.

Is there a way to have a moving average in Grafana?

I didn't find a 'moving average' feature and I'm wondering if there's a workaround.
I'm using influxdb as the backend.
Grafana supports adding a movingAverage(). I also had a hard time finding it in the docs, but you can (somewhat hilariously) see its usage on the feature intro page:
As is normal, click on the graph title, edit, add the metric movingAverage() as per described in the graphite documentation:
movingAverage(seriesList, windowSize)
Graphs the moving average of a metric (or metrics) over a fixed number of past points, or a time interval.
Takes one metric or a wildcard seriesList followed by a number N of datapoints or a quoted string with a length of time like ‘1hour’ or ‘5min’ (See from / until in the render_api_ for examples of time formats). Graphs the average of the preceding datapoints for each point on the graph. All previous datapoints are set to None at the beginning of the graph.
Example:
&target=movingAverage(Server.instance01.threads.busy,10)
&target=movingAverage(Server.instance*.threads.idle,'5min')
Grafana does no calculations itself, it just queries a backend and draws nice charts. So aggregating abilities depends solely on your backend. While Graphite supports windowing functions such as moving average, InfluxDB currently doesn't support it.
There are quite a lot requests for moving average in influxdb on the web. You can leave your "+1" and track progress in this ticket https://github.com/influxdb/influxdb/issues/77
Possible (yet not so easy) workaround is to create a custom script (cron, daemon, whatever) that will pre-calcuate MA and save it in a separate influxdb series.
I found myself here trying to do a moving average in Grafana with a PostgreSQL database, so I'll just add a way to do with a SQL query:
SELECT
date as time,
AVG(daily_average_column)
OVER(ORDER BY date ROWS BETWEEN 4 PRECEDING AND CURRENT ROW)
AS value,
'5 Day Moving Average' as metric
FROM daily_average_table
ORDER BY time ASC;
This uses a "window" function to average of the last 4 rows (plus the current row).
I'm sure there are ways to do this with MySQL as well.
Method and capability for this is dependent on your datasource.
You specified InfluxDB, so your query will need to wrap an 'Aggregation function' [ such as mean($field) ] within the moving_average($aggregation_function, $num_of_points) 'Transformation Function'.
In the 'Metrics' tab, you will find both the 'Transformation' functions in the 'select' portion of the menu.
Craft your query with the 'Aggregation function' (mean, min, max, etc.) first -- this way you can make sure the data looks as you expect it.
After this, just click the '+' button next to the 'Aggregation function', and under the menu 'Transformations', select 'moving_average'.
The number in brackets will be the number of points you want the average taken over.
Screenshot:
try avg_over_time(mymetric[5m])
InfluxDB 2 allows you to calculate the moving average in the query, e.g.:
from(bucket: "iot")
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r["_measurement"] == "PoolWeather")
|> filter(fn: (r) => r["_field"] == "batteryvoltage")
|> aggregateWindow(every: v.windowPeriod, fn: mean, createEmpty: false)
|> movingAverage(n: 10)
|> yield(name: "average")
Another option is to report the data as "timing" metrics and not counts.
This is easy to do especially with Statsd in your stack.
Plotting timing data (coming from statsd) as average of the reported data points is already built in.

D3 ticks() does not return value if provided scale has only 1 result

I have an x-axis that displays the days that my data occurs on. The data is dynamic and sometimes I have data for only 1 day, 2 days, n days, etc.
Here is my code for displaying the days on the x-axis:
chart.x = d3.time.scale()
.range([0, chart.w]);
chart.xAxis = d3.svg.axis()
.scale(chart.x)
.orient("bottom")
.ticks(d3.time.day) // --- TODO : this is not showing the current day, for some reason...
.tickFormat(d3.time.format("%b %-d %p"));
If my data is spread on 2 days (ex: Tuesday, Wednesday), this will only display a tick for the second day (Wednesday), ie. when the day "changes" from one to another.
I want to also display a tick for the first day (Tuesday).
Even if there is only data on 1 day, I still want to display a tick for it.
Thanks you guys,
To extend the domain so that the scale starts and ends at a tick mark you use the .nice() method, as #meetamit suggested -- but "nicing" only works if you call that method after you set the domain, so that's why you might not have noticed any change. The API doesn't really make that clear, although since the method alters the domain I suppose it makes sense that changing the domain later would over-ride the effect of a previous nice() call.
Also, be sure to use the time-scale version of the method: .nice(d3.time.day) to get a domain rounded off to the nearest day as opposed to just the nearest hour.
Here's a fiddle:
http://fiddle.jshell.net/4rGQq/
The key code is simply:
xScale.domain(d3.extent(d))
//d3.extent() returns max and min of array, which become the basic domain
.nice(d3.time.day);
//nice() extends the domain to nearest start/end of a day
Compare what happens if you comment out the .nice() call after setting the domain, even with the other .nice() call during initialization of the scale. Also compare what happens if you don't specify the day-interval as a parameter to the nice method.
Can you show how chart.x is set up? Hard to tell without seeing it, but you may be able to fix it by calling chart.x.nice() (see documentation).
Otherwise, seems like you'll need to manually check the extents of its domain, and adjust them in the case of single day.
Clarification
Your code shows how you call range() but not how you call domain(), which is the important one.
It seems to me to me that if do
var domain = chart.x.domain()
console.log domain[0] == domain[1]
you'll see true getting logged whenever the data is for only one day. If so, it means you're dealing with a single point in time rather than a time range. In that case, you'll need to adjust the domain to be a longer range.
Really hard to know without even seeing an image of what you're working on.
.ticks() should be used to set the number of ticks you'd like to have on your axis, not the kind of data that should be in them. So try to set it like .ticks(3) and it should set a couple of ticks.
From the wiki:
.ticks([count])
Returns approximately count representative values from the scale's input domain. If count is not specified, it defaults to 10. The returned tick values are uniformly spaced, have human-readable values (such as multiples of powers of 10), and are guaranteed to be within the extent of the input domain. Ticks are often used to display reference lines, or tick marks, in conjunction with the visualized data. The specified count is only a hint; the scale may return more or fewer values depending on the input domain.

How to get Fedex testing tracking number?

I'm configuring FEDEX shipping in Magento website. I got test account number, password, API key and meter number by login in test FEDEX account. I configured myself in Magento. Looks like everything fine. But I don't know how to test is Track Order.
So where can I get tracking number for shipping methods? Should I enter randomly or how can I get that? I tried some forum suggested numbers. But I got below error in my popup:
Tracking information is currently not available
I also checked my shipping_fedex log file in Magento. got logged some error codes in printed array. That's I give in below.
**ERROR log**
[result] => stdClass Object (
[HighestSeverity] => ERROR
[Notifications] => stdClass Object (
[Severity] => ERROR
[Source] => trck
[Code] => 6035
[Message] => Invalid tracking numbers. Please check the following numbers and resubmit.
[LocalizedMessage] => Invalid tracking numbers. Please check the following numbers and resubmit.
)
[Version] => stdClass Object (
[ServiceId] => trck
[Major] => 5
[Intermediate] => 0
[Minor] => 0
)
)
FEDEX help:
What Numbers Can I Track?
Track by Tracking Number: You can enter
up to 30 tracking numbers at a time. You can enter any combination of
FedEx Express, FedEx Express Freight, FedEx Ground, FedEx SmartPost,
FedEx Freight, or FedEx Custom Critical tracking numbers. Please
ensure that you enter only one tracking number per line.
Edit: I used "99999999999" as per Derek suggestion. But I got below response. Still same error in pop up. What does mean __pid =>2432?
Array
(
[request] => <?xml version="1.0" encoding="UTF-8"?>
<FDXTrack2Request xsi="http://www.w3.org/2001/XMLSchema-instance" noNamespaceSchemaLocation="FDXTrack2Request.xsd"><RequestHeader><AccountNumber>510087062</AccountNumber><MeterNumber>0</MeterNumber></RequestHeader><PackageIdentifier><Value>999999999999</Value></PackageIdentifier><DetailScans>1</DetailScans></FDXTrack2Request>
[result] =>
[__pid] => 2432
)
Your question is not at all stupid. I upvoted it.
The fedex documentation is horrible and doesn't mention how to use their services while testing and after moving to production. Their support is worse.
While I was rambling in the internet, I found a page mentioning the tracking number 123456789012 as a test number. Use it with your test credentials (key, password, account number and meter number), while you're setting your service path to https://wsbeta.fedex.com:443/web-services/track, and the request will return a valid response that you can build on.
Here’s a list of static tracking numbers that can be used in the FedEx test environment:
449044304137821 = Shipment information sent to FedEx
149331877648230 = Tendered
020207021381215 = Picked Up
403934084723025 = Arrived at FedEx location
920241085725456 = At local FedEx facility
568838414941 = At destination sort facility
039813852990618 = Departed FedEx location
231300687629630 = On FedEx vehicle for delivery
797806677146 = International shipment release
377101283611590 = Customer not available or business closed
852426136339213 = Local Delivery Restriction
797615467620 = Incorrect Address
957794015041323 = Unable to Deliver
076288115212522 = Returned to Sender/Shipper
581190049992 = International Clearance delay
122816215025810 = Delivered
843119172384577 = Hold at Location
070358180009382 = Shipment Canceled
In addition to: 123456789012
You can also use: 111111111111
** Every carrier (UPS, USPS, etc...) has lots of tracking numbers for lots of use-cases, but not FedEx... I find that very strange.
* Also... I am guessing FedEx expects you to use real tracking numbers even in their test environment. It's how I have been testing for multiple use-cases.
I hope this helps anyone, I have spent a while digging around.
On their website they list the tracking numbers you can use:
https://www.fedex.com/en-us/developer/web-services/process.html#develop
Expand the Testing Environment and Mock Tracking Numbers subheading.
Short answer
Use one of the tracking numbers from the table below (copied from Mock Tracking Numbers for FedEx Express and FedEx Ground) or number 123456789012, but mind that the FedEx Sandbox environment might be unstable during your testing and you might need to use FedEx API mocks instead (either built in-house using Wiremock or ready-made by a vendor).
Scan Event
Tracking Number
Track By Reference Info.
Shipment Account Number
Ship Date
Destination Postal Code
Shipment information sent to FedEx
449044304137821
Customer Reference: 115380173Ground Shipment ID: DMWsGWdnNN
510088000
15-08-2020
33126
Tendered
149331877648230
Ground Shipment ID: 149331877648230
510088000}]
15-08-2020
28752
Picked up
020207021381215
Ground Shipment ID: 53089528
510088000
15-08-2020
30549
Arrived at FedEx location
403934084723025
Ground Shipment ID: 403934084723025Department: 31826722
510088000
15-08-2020
99206
At local FedEx facility
920241085725456
Customer Reference: 0014243047/34684523 Ground Shipment ID: 920241085725456
510088000
15-08-2020
19720
At destination sort facility
568838414941
Shipper Reference: P218101_004154359Purchase Order: P218101_004154359
510088000
15-08-2020
85388
Departed FedEx location
039813852990618
Customer Reference: 4631962Ground Shipment ID: THE HOUSEDepartment: McGeePurchase Order: 3385158
510088000
15-08-2020
24740
On FedEx vehicle for delivery
231300687629630
Customer Reference: W62283340102Ground Shipment ID: 231300687629630Purchase Order: 6228334
510088000
15-08-2020
33126
International shipment release
797806677146
N/A
Customer not available or business closed (Delivery Exception 007)
377101283611590
Ground Shipment ID: 377101283611590
510088000
15-08-2020
95815
Local delivery restriction (Delivery Exception 083)
852426136339213
Customer Reference: 118402713013
510088000
15-08-2020
11375
Incorrect address (Delivery Exception 03)
797615467620
Shipper Reference: OTHER-TK104
510088000
15-08-2020
70810
Unable to deliver (Shipment Exception 099)
957794015041323
N/A
Returned to sender/shipper
076288115212522
Invoice: 81909
510088000
15-08-2020
50323
Clearance delay (International)
581190049992
N/A
Delivered
122816215025810
Customer Reference: PO#174724
510088000
15-08-2020
24273
Hold at location
843119172384577
N/A
Shipment canceled
070358180009382
Customer Reference: 15241402Ground Shipment ID: 070358180009382
510088000
15-08-2020
94545
Duplicate Tracking Number
713062653486
Unique Identifier 1: 2457821000~713062653486~FXUnique Identifier 2: 2457835000~713062653486~FX
Long answer
The FedEx Sandbox has numerous stability and test data problems. For example, if you use tracking code 123456789012 you will get a different response status depending on the state of the FedEx Sandbox environment.
If you are performing a one-off manual test of your Magento integration with FedEx API, then using the FedEx Sandbox should be sufficient, and you can go ahead and use one of the codes provided above.
If however, you are running automated regression or integration tests on a schedule or per commit then the instability of the environment might cripple your testing. For example, you might see flaky tests and flaky builds and have to spend time investigating them even though there is nothing wrong with your code or tests, it's just an issue with the FedEx Sandbox API.
To resolve the issue with FedEx Sandbox environment stability you have three options, which are essentially about using test-doubles instead of the real FedEx Sandbox API:
Create and use mocks in your code instead of using the FedEx Sandbox. For example, Mockito in Java or uniuttest.mock in Python. This means you will have to write the FedEx Mockito mocks yourself. And it comes with several tradeoffs.
Create over-the-wire mocks with tools like Wiremock or Mountebank instead of using the FedEx Sandbox. There is a list of tools like that on Wikipedia. The issue here again is that you have to build those over-the-wire mocks yourself, which can be problematic if it's more than one API and you have a lot of work on your plate anyway.
Use ready-made FedEx API mocks like the one from Traffic Parrot instead of using the FedEx Sandbox. The advantage is they are created by experts and you can use them within minutes, just copy their mock API URL and use it instead of the FedEx one. You will have to pay for using them, which can sometimes be a downside of this option.
Here is a good one I pulled out of a code sample in the developer docs.
797843158299
The above list of tracking numbers will indeed work when pointed to the following server endpoint:
https://wsbeta.fedex.com:443/web-services/track
Note that the only time these numbers will not work is during FedEx's scheduled maintenance windows.
You may try getting the ship functionality working first. That will provide you a tracking no that can be used in testing tracking. I did it this way and it works for me!
We're trying to understand FEDEX tracking number testing too. I found this resource. But so far I'm not sure if the numbers work.
We'll update the answer later if we determine it helped or delete it if it does not:
https://www.fedex.com/us/developer/webhelp/ws/2019/US/index.htm#t=wsdvg%2FAppendix_F_Test_Server_Mock_Tracking_Numbers.htm

How to verify web text while excluding random vars with ruby/watir

I have this text and need to verify the bolded words only in each line:
Insured Direct Bill / 16.67%: $xxx.xx down, includes the Policy Fee and Financial Responsibility Fee, and 5 installments of $xxx.xx (does not include $x.xx installment fee)
Insured Direct Bill / 25%: $xxx.xx down, includes the Policy Fee and Financial Responsibility Fee, and 5 installments of $xxx.xx (does not include $x.xx installment fee)
Electronic Funds Transfer: $xxx.xx down, includes the Policy Fee and Financial Responsibility Fee, and 5 installments of $xxx.xx (does not include $x.xx installment fee)
I'm assuming I'll need to use:
foo = REGEX
#browser.text.include?(foo)
I'm stuck at how to get it to see everything other than the currency amounts. [^$\d+.\d+] excludes all the currency but includs the 5 and 16.67
Thanks
regex = /Insured Direct Bill \/ 25%: \$(\d+\.\d+) down, includes the Policy Fee and Financial Responsibility Fee, and 5 installments of \$(\d+\.\d+) \(does not include \$(\d+\.\d+) installment fee\)/
#browser.text.match(regex)
There are some regex lessons in Marick's book Everyday Scripting with Ruby. I recommend them to strengthen your capability if you need to use regex from time to time.

Resources