price from env

This commit is contained in:
tavo 2024-09-22 10:00:15 -06:00
parent e357a8c270
commit c711b6707d
2 changed files with 6 additions and 6 deletions

View file

@ -69,7 +69,7 @@ func main() {
returnURL = os.Getenv("RETURN_URL")
cancelURL = os.Getenv("CANCEL_URL")
port = os.Getenv("PORT")
// price = os.Getenv("PRICE")
amount = os.Getenv("PRICE")
)
if baseURL == "" ||
@ -124,7 +124,7 @@ func main() {
s3Client = s3.NewFromConfig(cfg)
http.HandleFunc("/api/orders", CreateOrderHandler(db))
http.HandleFunc("/api/orders", CreateOrderHandler(db, amount))
http.HandleFunc("/api/orders/", CaptureOrderHandler(db))
http.HandleFunc("/api/update", UpdateSiteHandler(db))
http.HandleFunc("/api/confirm", ConfirmChangesHandler(db))
@ -169,7 +169,7 @@ func fatal(err error, notice string) {
log.Fatalf("%s: %v", notice, err)
}
func CreateOrderHandler(db *sql.DB) http.HandlerFunc {
func CreateOrderHandler(db *sql.DB, amount string) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var cart struct {
Directory string `json:"directory"`
@ -191,7 +191,7 @@ func CreateOrderHandler(db *sql.DB) http.HandlerFunc {
return
}
orderID, err := CreateOrder()
orderID, err := CreateOrder(amount)
if err != nil {
httpErrorAndLog(w, err, errCreateOrder, "Error creating order")
return

View file

@ -91,7 +91,7 @@ func Token() (string, error) {
return response.AccessToken, nil
}
func CreateOrder() (string, error) {
func CreateOrder(amount string) (string, error) {
token, err := Token()
if err != nil {
return "", fmt.Errorf("%s: %v", errToken, err)
@ -129,7 +129,7 @@ func CreateOrder() (string, error) {
Intent: "CAPTURE",
PurchaseUnits: []PurchaseUnits{{Amount: Amount{
CurrencyCode: "USD",
Value: os.Getenv("PRICE"),
Value: amount,
}}},
PaymentSource: PaymentSource{Paypal: Paypal{Address: Address{
CountryCode: "CR",