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

How to check for error code when calling GetTransactionInfo #300

Open
Bevilacqua opened this issue Nov 14, 2024 · 2 comments
Open

How to check for error code when calling GetTransactionInfo #300

Bevilacqua opened this issue Nov 14, 2024 · 2 comments

Comments

@Bevilacqua
Copy link

The README explains:

If you're unsure about the environment, follow these steps:

  • Initiate a call to the endpoint using the production URL. If the call is successful, the transaction identifier is associated with the production environment.
  • If you encounter an error code 4040010, indicating a TransactionIdNotFoundError, make a call to the endpoint using the sandbox URL.
  • If this call is successful, the transaction identifier is associated with the sandbox environment. If the call fails with the same error code, the transaction identifier doesn't exist in either environment.

How do you actually check the error code? The function only returns the response (which will be nil when there is an error) and an error. The error has the code embedded in the error string but is there a straight forward way to check what error code so we know when to try again with the sandbox URL?

@richzw
Copy link
Collaborator

richzw commented Nov 14, 2024

The errors are custom error, you could find more details from here https://github.com/awa/go-iap/blob/master/appstore/api/error.go. You could fetch the error code through ErrorCode()

@Bevilacqua

@richzw
Copy link
Collaborator

richzw commented Nov 15, 2024

Sample codes

func (c *APIClient) Verify(ctx context.Context, transactionId string) (interface{}, error) {
	result, err := c.productionCli.GetTransactionInfo(ctx, transactionId)
	if err != nil && errors.Is(err, TransactionIdNotFoundError) {
		result, err = c.sandboxCli.GetTransactionInfo(ctx, transactionId)
	}

https://github.com/awa/go-iap/blob/master/appstore/api/validator.go#L26 @Bevilacqua

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

No branches or pull requests

2 participants