Skip to content

Commit

Permalink
add zibal verify step
Browse files Browse the repository at this point in the history
  • Loading branch information
mohammadv184 committed Jan 13, 2022
1 parent f4c2bde commit bc09ed9
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions gateway/zibal/verify.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package zibal

import (
"encoding/json"

e "github.com/mohammadv184/gopayment/errors"
"github.com/mohammadv184/gopayment/receipt"
)

// VerifyRequest is the request struct for verify
type VerifyRequest struct {
TrackID string `json:"track_id"`
}

// Verify is the function to verify a payment
func (d *Driver) Verify(vReq interface{}) (*receipt.Receipt, error) {
verifyReq, ok := vReq.(*VerifyRequest)
if !ok {
return nil, e.ErrInternal{
Message: "vReq is not of type VerifyRequest",
}
}
resp, _ := client.Post(APIVerifyURL, map[string]string{
"trackId": verifyReq.TrackID,
"merchant": d.Merchant,
}, nil)

var res map[string]interface{}
err := json.Unmarshal(resp.Body(), &res)
if err != nil {
return nil, err
}

if resp.StatusCode() != 200 || res["result"].(float64) != 100 {
return nil, e.ErrPurchaseFailed{
Message: res["message"].(string),
}
}

rec := receipt.NewReceipt(res["refNumber"].(string), d.GetDriverName())
rec.Detail("cardNumber", res["cardNumber"].(string))
return rec, nil
}

0 comments on commit bc09ed9

Please sign in to comment.