Last active
March 2, 2023 13:45
-
-
Save opensaucerer/f74f8d1f633e0daf7a647d663919734a to your computer and use it in GitHub Desktop.
Revisions
-
opensaucerer revised this gist
Mar 2, 2023 . 1 changed file with 10 additions and 8 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -10,7 +10,15 @@ import ( "github.com/samperfect/goaxios" ) type PaymentResponse struct { Data struct { Link string `json:"link"` } `json:"data"` Status string `json:"status"` Message string `json:"message"` } func (order Order) StoreTransactions() (PaymentResponse, error) { config, _ := config.LoadConfig(".") var payment Payment query := `INSERT INTO payments(amount, reference,payment_method,created_at) @@ -31,13 +39,7 @@ func (order Order) StoreTransactions() (interface{}, error) { return nil, err } var paymentResponse PaymentResponse err = json.Unmarshal(res, &paymentResponse) if err != nil { -
opensaucerer revised this gist
Mar 2, 2023 . 1 changed file with 15 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -2,6 +2,7 @@ package main import ( "context" "encoding/json" "strconv" "time" @@ -30,7 +31,20 @@ func (order Order) StoreTransactions() (interface{}, error) { return nil, err } var paymentResponse struct { Data struct { Link string `json:"link"` } `json:"data"` Status string `json:"status"` Message string `json:"message"` } err = json.Unmarshal(res, &paymentResponse) if err != nil { return nil, err } return paymentResponse, nil } func InitiateCharge() ([]byte, error) { -
opensaucerer renamed this gist
Mar 2, 2023 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
opensaucerer created this gist
Mar 2, 2023 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,68 @@ package main import ( "context" "strconv" "time" "github.com/jackc/pgx/v5" "github.com/samperfect/goaxios" ) func (order Order) StoreTransactions() (interface{}, error) { 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") } res, err := InitiateCharge() if err != nil { return nil, err } return res, nil } func InitiateCharge() ([]byte, error) { body := map[string]interface{}{ "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, } // tweet the message r := goaxios.GoAxios{ Url: config.PAYMENTURL, Method: "POST", BearerToken: "Your Flutterwave Secret Key", Body: body, } // send request _, b, _, err := r.RunRest() if err != nil { return nil, err } return b, nil }