Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Intermittent problem creating order #33

Closed
rudolfl opened this issue Jul 6, 2017 · 9 comments
Closed

Intermittent problem creating order #33

rudolfl opened this issue Jul 6, 2017 · 9 comments

Comments

@rudolfl
Copy link

rudolfl commented Jul 6, 2017

Sometimes, following code:
$orderToken = \CultureKings\Afterpay\Factory\MerchantApi::orders($authorization)->create($orderDetails);

returns NULL. No exception, just NULL.

Problem is intermittent and I am trying to find a way to reliably reproduce it. No luck so far, but it pops every now and then.
Any idea what can trigger it?

Additional info -- I found that problem is related when product info is set. Some products trigger the issue.
I tried to break it, but fail to reproduce the problem. Someone who is using module I wrote based on your code is experiencing the fault on certain products. I tried to use his product data (name, SKU, price), but that works for me. Really weird!

Rudolf

@rudolfl
Copy link
Author

rudolfl commented Jul 8, 2017

HI,
Got to the bottom of this.
Problem is actually at Afterpay side. They don't like getting item price (Money model) which is not rounded to 2 decimal places. If price is, for whatever reason, has more than 2 decimal places, Afterpay spits a dummy.
I fixed this before calling Money:setPrice() in my code, but, as a suggestion, may be it is worth doing in your code as well inside of said function.

Rudolf

@jared-fraser
Copy link
Contributor

Cheers @rudolfl. I'll have a play around and see if there is a way I can highlight the issue better in an error.

My main concern is that I do not want to be doing any rounding or mutating of values in the library before passing it off to afterpay. Final price should always be specified by the project so there is not any confusion.

I may look into validation, however I tried to leave this to afterpay to do on behalf of the library.

@rudolfl
Copy link
Author

rudolfl commented Jul 9, 2017 via email

@jared-fraser
Copy link
Contributor

@rudolfl is this the error that your seeing?

CultureKings\Afterpay\Model\ErrorResponse {#154
  #errorCode: "invalid_json"
  #errorId: "462761d252297eb9"
  #message: "The request contains improperly formated JSON"
  #httpStatusCode: 400
}

Definitely appears to be an issue on afterpay's end. The JSON I am sending is valid

{
	"consumer": {},
	"items": [],
	"discounts": [],
	"totalAmount": {
		"amount": 203.4443,
		"currency": "AUD"
	},
	"merchant": {}
}

but throws an invalid json error. If i change it to 2 decimal spots I get a correct validation error for missing required fields.

@rudolfl
Copy link
Author

rudolfl commented Jul 10, 2017 via email

@jared-fraser
Copy link
Contributor

Thanks for the report.

I have updated the README to point out this issue and given you credit for the bug report.
I have also contacted afterpay support to let them know of the bug.

As this lies outside the scope of the library I am going to close the issue now.

@vangar02
Copy link

It appears something in your API will need to change. I tried setting 2 decimal places as a string, i tried setting the float to 2 decimal places. But after setAmount() is called on the money object, no matter what I do it seems to send a float with a large amount of decimal places to afterpay.

@Jore
Copy link
Contributor

Jore commented Jun 18, 2020

@vangar02 can you replicate the issue using postman?

cc @jared-fraser

@vangar02
Copy link

vangar02 commented Jun 22, 2020

Not exactly sure how this would help @Jore , because the number becomes a float in the setAmount() method in the CultureKings/AfterPay php API. Sending a number in JSON direct to afterpay with postman would not cause the issue, see Jared's message above. EDIT: Actually, unsure if it happens in the setAmount, or when the json is prepared after that object, before sending to Afterpay.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants