Created
March 2, 2023 11:40
-
-
Save CodeNinjaUG/d23f9532c9d55d47794354056fd73291 to your computer and use it in GitHub Desktop.
testing to see if the method returns an interface
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func (order Order) StoreTransactions() interface{} { | |
config, _ := config.LoadConfig(".") | |
var payment Payment | |
query := `INSERT INTO payments(amount, reference,payment_method,created_at) | |
VALUES(@paymentAmount, @paymentReference, @paymentMethod, @paymentCreatedAt) return(id)` | |
trans := pgx.NamedArgs{ | |
"paymentAmount": order.Total, | |
"paymentReference": Random(20), | |
"paymentMethod": "Cash", | |
"paymentCreatedAt" : time.Now(), | |
} | |
err := database.DB.QueryRow(context.Background(),query, trans).Scan(&payment.Id); | |
if err != nil { | |
panic("Could Execute this Query") | |
} | |
data := map[string]string{ | |
"req" : "card_payment", | |
"currency" : "USD", | |
"fname" : order.Customer.FirstName, | |
"lname" : order.Customer.LastName, | |
"encryption_key":config.DBENCRYPTION, | |
"amount": strconv.FormatFloat(order.Total,'E',-1,64), | |
"emailAddress" : order.Customer.Email, | |
"call_back" : config.CALLBACKURL, | |
"success_url": config.SUCCESSURL, | |
"failure_url" : config.FAILUREURL, | |
// "phone" : order.Customer.Phone, | |
"description" : "payments", | |
"txRef" : payment.Reference, | |
} | |
payload, _:= json.Marshal(data) | |
req, err := http.NewRequest("POST",config.PAYMENTURL,strings.NewReader(string(payload))) | |
if err !=nil{ | |
return err | |
} | |
req.Header.Add("Accept", "application/json") | |
req.Header.Add("Content-Type", "application/json") | |
resp, err := http.DefaultClient.Do(req) | |
if err != nil { | |
return err | |
} | |
var res map[string]interface{} | |
if err := json.NewDecoder(resp.Body).Decode(&res); err!=nil { | |
return err | |
} | |
return res | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment