BAD VALUE: order_tax_amount - ruby-on-rails

I'm trying to send request using Postman to test Klarna payment, According to this API DOC, We use POST /checkout/v3/orders to send a request so that we can create order (For the testing environment they use https://api.playground.klarna.com/ + rest of url), But when i'm trying to send the given example in the above link(on the right side), It says that
{ "error_code" : "BAD_VALUE", "error_messages" : [ "Bad value: order_tax_amount" ], "correlation_id" : "12255531-ffcb-4a91-a375-04577fca78e5" }
When i read what does it require in the documentation, It says that the value should be formatted in some formula ±1 of total_amount - total_amount * 10000 / (10000 + tax_rate), When i calculate that the result 4545.4545 when i change the value in the request and try again, It gives the same error.
Can anybody help me with that?
Thanks

The docs you've linked say that order_tax_amount should be an integer of minor currency units, so it sounds like 4545.4545 isn't a valid value!
You should choose which direction you want to round in, then send an integer value instead.

I found the problem, I should change both total_tax_amount and order_tax_amount to be 4545, What a mistake, I think they should update this in their documentation so people be more familiar with it.

Related

Is it possible to call an URL passing website parameters?

I am writing code for a custom SAP program regarding some Vendor information. In my program flow, there is a possibility of me trying to use a Vendor VAT Number that belongs to an unknown Vendor. There is a Web site (EU Based - https://ec.europa.eu/taxation_customs/vies/) for such purposes that requires a country key and the specified VAT Number in order for it to provide an answer with the available Company information (only works for company VAT numbers of course). My problem is that I cannot seem to find any way to pass those parameters dynamically to the Web site without needing the user to interfere during this process. Manually, the process would be to select a country key, type in a VAT number and press 'Verify'.
Is there any way for me to call this specific Web site URL and "bypass" this process to only display the result page? For now, I'm using the following Function Module to just call the specified URL, in lack of any better choices.
call function 'CALL_INTERNET_ADRESS'
exporting
pi_adress = 'https://ec.europa.eu/taxation_customs/vies/'
exceptions
no_input_data = 1
others = 2.
You can use CL_HTTP_CLIENT class or HTTP_POST/HTPP_GET FM.
You need to install given web page SSL root certificate to your system with STRUST t-code.
Example usage of CL_HTTP_CLIENT below.
DATA: lv_url TYPE string VALUE 'http://mkysoft.com/ip.php'.
DATA: o_client TYPE REF TO if_http_client.
DATA: lv_http_rc TYPE i.
DATA: lv_reason TYPE string.
DATA: lt_fields TYPE tihttpnvp.
TRY.
cl_http_client=>create_by_url( EXPORTING
url = lv_url
IMPORTING
client = o_client
EXCEPTIONS
OTHERS = 0 ).
o_client->request->get_header_fields( CHANGING fields = lt_fields ).
o_client->request->set_header_field( name = '~request_uri' value = '/ip.php' ).
o_client->request->set_header_field( name = '~host' value = 'mkysoft.com' ).
o_client->request->set_method( if_http_request=>co_request_method_get ).
o_client->send( ).
o_client->receive( ).
o_client->response->get_status( IMPORTING
code = lv_http_rc
reason = lv_reason ).
* Error check
IF lv_http_rc = 200.
DATA(lv_xml) = o_client->response->get_cdata( ).
* Handle error
ELSE.
WRITE: / 'Fehler: ', lv_http_rc.
ENDIF.
o_client->close( ).
CATCH cx_root INTO DATA(e_txt).
WRITE: / e_txt->get_text( ).
ENDTRY.
EU Commission has a SOAP service for vat numbers.
See the info page
https://ec.europa.eu/taxation_customs/vies/technicalInformation.html
and that it even supports http
http://ec.europa.eu/taxation_customs/vies/checkVatTestService.wsdl
You have a non screen scrape method, proper interface you should look at.
On the other point of Avoiding SSL.
Make a basic guide for customers to add the European commission cert to their SAP system. If someone is complaining about that, then they are a serious user of the internet. Every sap on premise user, that needs to call the internet adds certs.
Http is dead....

getAdGroupBidLandscape returning no campaigns found

I'm trying to use the Google AdWords bid simulator system to try and get some insights out of the AdWords bid simulator. More specifically I'm using the AdGroupBidLandscape() functionality, but it's returning 'No Campaigns Found', but we definitely have campaigns where the Bid Simulator tool works through the AdWords web page interface, so I'm a bit confused. Here is the code I'm running, and yes I know I'm only retrieving a single field - I'm just trying to keep things as simple as possible.
from googleads import adwords
import logging
import time
CHUNK_SIZE = 16 * 1024
PAGE_SIZE = 100
logging.basicConfig(level=logging.INFO)
logging.getLogger('suds.transport').setLevel(logging.DEBUG)
adwords_client = adwords.AdWordsClient.LoadFromStorage()
dataService = adwords_client.GetService('DataService', version='v201710')
offset = 0
selector = {'fields':['Bid'], #'impressions', 'promotedImpressions', 'requiredBudget', 'bidModifier', 'totalLocalImpressions', 'totalLocalClicks', 'totalLocalCost', 'totalLocalPromotedImpressions'],
'paging': {
'startIndex': str(offset),
'numberResults': str(PAGE_SIZE)
}
}
more_pages = True
while more_pages:
page = dataService.getAdGroupBidLandscape(selector)
# Display results.
if 'entries' in page:
for campaign in page['entries']:
print ('Campaign with id "%s", name "%s", and status "%s" was '
'found.' % (campaign['id'], campaign['name'],
campaign['status']))
else:
print 'No campaigns were found.'
offset += PAGE_SIZE
selector['paging']['startIndex'] = str(offset)
more_pages = offset < int(page['totalNumEntries'])
time.sleep(1)
We have several different accounts attachd to AdWords. My account is the only one that has developer API access, so I sort of wonder if the problem is that my account isn't the primary account associated with the campaigns- I just have one of the few administrator accounts. Can anyone provide some insights about this for me?
Thanks,
Brad
The solution I found to this problem was to add a predicate to the selector specifying a particular CampaignId. While that doesn't make any sense to me that it would fix it, because it should really just be filtering the data with that if I understand things correctly, it seems to have. I don't have a good explanation for that, but I thought someone else might find this useful. If I come to realize this wasn't the fix to the problem I had, I will come back and update this answer.

Array.size() returned wrong values (Grails)

I'm developing an app using Grails. I want to get length of array.
I got a wrong value. Here is my code,
def Medias = params.medias
println params.medias // I got [37, 40]
println params.medias.size() // I got 7 but it should be 2
What I did wrong ?
Thanks for help.
What is params.medias (where is it being set)?
If Grials is treating it as a string, then using size() will return the length of the string, rather than an array.
Does:
println params.medias.length
also return 7?
You can check what Grails thinks an object is by using the assert keyword.
If it is indeed a string, you can try the following code to convert it into an array:
def mediasArray = Eval.me(params.medias)
println mediasArray.size()
The downside of this is that Eval presents the possibility of unwanted code execution if the params.medias is provided by an end user, or can be maliciously modified outside of your compiled code.
A good snippet on the "evil (or lack thereof) of eval" is here if you're interested (not mine):
https://javascriptweblog.wordpress.com/2010/04/19/how-evil-is-eval/
I think 7 is result of length of the string : "[37,40]"
Seems your media variable is an array not a collection
Try : params.medias.length
Thanks to everyone. I've found my mistake
First of all, I sent an array from client and my params.medias returned null,so I converted it to string but it is a wrong way.
Finally, I sent and array from client as array and in the grails, I got a params by
params."medias[]"
List medias = params.list('medias')
Documentation: http://grails.github.io/grails-doc/latest/guide/single.html#typeConverters

JSON Parsing issue in Rails

I am seeing a strange issue in Rails.
Request Body (request.body):
renewals[][driver_1][dl_number]=123&
renewals[][driver_1][expiration_date]=20130513&
renewals[][driver_1][last_name]=123&
renewals[][driver_1][state]=AL&
renewals[][driver_1][verified]=1&
renewals[][driver_2][verified]=0&
renewals[][id]=6415&
renewals[][insurance][expiration_date]=20130513&
renewals[][insurance][naic]=123&
renewals[][insurance][policy_number]=123&
renewals[][insurance][verified]=1&
renewals[][mailing_address][address_has_changed]=0&
renewals[][mailing_address][city]=GULF%20SHORES&
renewals[][mailing_address][state]=AL&
renewals[][mailing_address][street_address]=8094%20BEACH%20LANE&
renewals[][mailing_address][zip]=35023&
renewals[][driver_1][dl_number]=123&
renewals[][driver_1][last_name]=123&
renewals[][driver_1][state]=AL&
renewals[][driver_1][verified]=1&
renewals[][driver_2][verified]=0&
renewals[][id]=6412&
renewals[][insurance][expiration_date]=20130513&
renewals[][insurance][naic]=123&
renewals[][insurance][policy_number]=123&
renewals[][insurance][verified]=1&
renewals[][mailing_address][address_has_changed]=0&
renewals[][mailing_address][city]=HUEYTOWN&
renewals[][mailing_address][state]=AL&
renewals[][mailing_address][street_address]=123%20ANY%20LANE&
renewals[][mailing_address][zip]=35023&
renewals[][driver_1][dl_number]=123&
renewals[][driver_1][last_name]=123&
renewals[][driver_1][state]=AL&
renewals[][driver_1][verified]=1&
renewals[][driver_2][verified]=0&
renewals[][id]=6411&
renewals[][insurance][expiration_date]=20130513&
renewals[][insurance][naic]=123&
renewals[][insurance][policy_number]=123&
renewals[][insurance][verified]=1&
renewals[][mailing_address][address_has_changed]=0&
renewals[][mailing_address][city]=HUEYTOWN&
renewals[][mailing_address][state]=AL&
renewals[][mailing_address][street_address]=104%20MERRIMONT%20ROAD&
renewals[][mailing_address][zip]=35023&
JSON Parsed Params (params[:renewals]): https://gist.github.com/t2/5566652
Notice in the JSON that the driver_1 information is missing on the last record. Not sure why this is. The data is in the request. Any known bug I am missing? Let me know if you need more info.
Unfortunately this is just how Rails parses JSON like this (where your [] is massively nested). I've come up against this before - http://guides.rubyonrails.org/form_helpers.html#combining-them gave some explanation.
From what I remember, if you can put in numeric keys rather than just [] (i.e. [1] for the first one, [2] for the second etc.) then it will work as you want it to.
So I figured it out. I needed to set the requestSerializationMIMEType to RKMIMETypeJSON.

Ad Asp.Net Changing Passwords

We're using ASP.NET MVC and AdMembership provider for login, and for various reasons had to implement our own "Change Password on next Login" functionality.
We also have a nist requirement of not allowing more than one change per 24 hours. so it's set up that way in AD.
What we need is to Ignore that one requirement when resetting a password to default, we want the student to be forced to change the password on the next logon, even if it's before 24 hours.
here is my stab at it. Basically I want to change the PwdLastSet property to a value more than 24 hours old after we reset the password.
if ( bSetToDefault )
{
var adDate = userToActOn.ADEntry.Properties[ "PwdLastSet" ][ 0 ];
DateTime passwordLastSet = DateTime.FromFileTime( ( Int64 ) adDate );
passwordLastSet = System.DateTime.Now.AddHours( -25 );
long filetime = passwordLastSet.ToFileTimeUtc();
userToActOn.ADEntry.Properties[ "PwdLastSet" ][ 0 ] = filetime;
}
But I keep getting null back even when I know the users password has been changed.
anyone got any hints or suggestions? Am I looking in the wrong property?
hmm this attribute is replicated so should always be available.
Try the command line script to see if it shows up:
http://www.rlmueller.net/PwdLastChanged.htm
Its possible because its a 64bit date and not doing a conversion? Try the script though and see if it works. if it does, then look at the Integer8Date procedure in it for your date conversion.
If you use System.DirectoryServices.AccountManagement then there is an exposed method for the User Principal to expire the password immediately. So it will be as easy as calling it like such oUserPrincipal.ExpirePasswordNow(); for more info about using it please see this article.

Resources