Doesn't get error when create transaction with order id containing space
imampri100 opened this issue · 2 comments
Hello @Xaxxis
I'm experiencing error 404: Transaction doesn't exist. after create transaction with order id containing space
import "github.com/midtrans/midtrans-go/snap"
func main() {
orderID := "testing foo bar"
// Create transaction to midtrans
s := snap.Client{}
s.New(credential.ServerKey, credential.EnvironmentType)
req := snap.Request{
TransactionDetails: midtrans.TransactionDetails{
OrderID: orderID,
GrossAmt: 100000,
},
}
snapResp, err := s.CreateTransaction(&req)
if err != nil {
fmt.Println(err) // Will not return error
}
// ===== Pay using snap midtrans ====== //
// Check to midtrans, is order id valid?
var midtransClient coreapi.Client
midtransClient.New(credential.ServerKey, midtrans.Sandbox)
trxResp, err := midtransClient.CheckTransaction(orderID)
if err != nil {
fmt.Println(err) // Will return error 404, transaction not found
}
}
Can't order id containing space?
If order id can't containing space, please make an error when order id is not valid in future release
Let me know if this issue is relevant
Thanks
Hello @imampri100 , when generating the Snap transaction, it's possible for the order-id to include spaces. However, it's important to ensure that the order-id remains URL-safe. The accepted symbols for the order-id are dash (-), underscore (_), tilde (~), and dot (.). Failure to adhere to this might lead to a 404 error upon calling the checkTransaction function using param order-id, since this function employs the HTTP GET method and spaces are not considered URL-safe. Alternatively, if your order-id does have spaces, you can utilize the transaction_id value to verify the transaction.
Thank You
Hello @Xaxxis
I see, so the 404 error when calling the checkTransaction function is caused by using an order-id that is not considered URL-safe, such as space characters.
Alternatively, I should use transaction_id to verify the transaction instead of order_id.
Thanks for your support