diff --git a/.env.example b/.env.example index 4d13e9d8..d171dddf 100644 --- a/.env.example +++ b/.env.example @@ -18,7 +18,8 @@ STRIPE_ACCOUNT_COUNTRY=US # Supported payment methods for the store. # Some payment methods support only a subset of currencies. # Make sure to check the docs: https://stripe.com/docs/sources -# Only used for the python server. For Node.js see the server/node/config.js file! +# Only used for servers that don't have a separate config/settings file. +# For Node.js see the server/node/config.js file! PAYMENT_METHODS="alipay, bancontact, card, eps, ideal, giropay, multibanco, sofort, wechat" # Optional ngrok configuration for development (if you have a paid ngrok account). diff --git a/.gcloudignore b/.gcloudignore index afb3de6e..b34dd11a 100644 --- a/.gcloudignore +++ b/.gcloudignore @@ -17,6 +17,7 @@ node_modules/ # Alternative server implementations +server/go/ server/java/ server/php/ server/python/ diff --git a/README.md b/README.md index ced9c02c..fcd58106 100644 --- a/README.md +++ b/README.md @@ -63,6 +63,7 @@ The [Sources API](https://stripe.com/docs/sources) provides a single integration Instructions for running the Node.js server in [`server/node`](/server/node) are below. You can find alternative server implementations in the [`server`](/server) directory: +- Go, Echo: [`server/go`](/server/java) - Java, Spark: [`server/java`](/server/java) - Node, Express: [`server/node`](/server/node) - PHP, Slim: [`server/php`](/server/php) diff --git a/public/javascripts/store.js b/public/javascripts/store.js index a548e93e..4f53c6b4 100644 --- a/public/javascripts/store.js +++ b/public/javascripts/store.js @@ -57,7 +57,7 @@ class Store { // Retrieve a SKU for the Product where the API Version is newer and doesn't include them on v1/product async loadSkus(product_id) { try { - const response = await fetch(`/product/${product_id}/skus`); + const response = await fetch(`/products/${product_id}/skus`); const skus = await response.json(); this.products[product_id].skus = skus; } catch (err) { diff --git a/server/go/app.go b/server/go/app.go index 055fbe05..19734469 100644 --- a/server/go/app.go +++ b/server/go/app.go @@ -86,7 +86,7 @@ func buildEcho(publicDirectory string) *echo.Echo { return c.JSON(http.StatusOK, listing{products}) }) - e.GET("/product/:product_id/skus", func(c echo.Context) error { + e.GET("/products/:product_id/skus", func(c echo.Context) error { skus, err := inventory.ListSKUs(c.Param("product_id")) if err != nil { return err diff --git a/server/go/setup/setup.go b/server/go/setup/setup.go index 40f0769e..98f63441 100644 --- a/server/go/setup/setup.go +++ b/server/go/setup/setup.go @@ -6,6 +6,8 @@ import ( "github.com/stripe/stripe-go" "github.com/stripe/stripe-go/product" "github.com/stripe/stripe-go/sku" + + "github.com/stripe/stripe-payments-demo/config" ) func CreateData() error { @@ -14,7 +16,7 @@ func CreateData() error { return fmt.Errorf("setup: error creating products: %v", err) } - err = createSKUs() + err = createSKUs(config.Default().Currency) if err != nil { return fmt.Errorf("setup: error creating products: %v", err) } @@ -87,7 +89,7 @@ func createProducts() error { return nil } -func createSKUs() error { +func createSKUs(currency string) error { paramses := []*stripe.SKUParams{ { ID: stripe.String("increment-03"), @@ -96,7 +98,7 @@ func createSKUs() error { "issue": "Issue #3 “Development”", }, Price: stripe.Int64(399), - Currency: stripe.String(string(stripe.CurrencyUSD)), + Currency: stripe.String(currency), Inventory: &stripe.InventoryParams{ Type: stripe.String(string(stripe.SKUInventoryTypeInfinite)), }, @@ -109,7 +111,7 @@ func createSKUs() error { "gender": "Woman", }, Price: stripe.Int64(999), - Currency: stripe.String(string(stripe.CurrencyUSD)), + Currency: stripe.String(currency), Inventory: &stripe.InventoryParams{ Type: stripe.String(string(stripe.SKUInventoryTypeInfinite)), }, @@ -121,7 +123,7 @@ func createSKUs() error { "set": "Collector Set", }, Price: stripe.Int64(799), - Currency: stripe.String(string(stripe.CurrencyUSD)), + Currency: stripe.String(currency), Inventory: &stripe.InventoryParams{ Quantity: stripe.Int64(500), Type: stripe.String(string(stripe.SKUInventoryTypeFinite)), diff --git a/server/go/webhooks/webhooks.go b/server/go/webhooks/webhooks.go index 7b54a99c..320fc719 100644 --- a/server/go/webhooks/webhooks.go +++ b/server/go/webhooks/webhooks.go @@ -18,7 +18,7 @@ func HandlePaymentIntent(event stripe.Event, pi *stripe.PaymentIntent) (bool, er if pi.LastPaymentError.PaymentMethod != nil { fmt.Printf( "🔔 Webhook received! Payment on %s %s for PaymentIntent %s failed\n", - "payment_intent", + "payment_method", pi.LastPaymentError.PaymentMethod.ID, pi.ID, ) diff --git a/server/java/src/main/java/app/Application.java b/server/java/src/main/java/app/Application.java index 185a8584..5907238e 100644 --- a/server/java/src/main/java/app/Application.java +++ b/server/java/src/main/java/app/Application.java @@ -17,7 +17,7 @@ public static void main(String[] args) { get("/config", ConfigController.getConfig); get("/products", ProductController.getProducts); get("/products/:id", ProductController.getProduct); - get("/product/:id/skus", ProductController.getSKUsForProduct); + get("/products/:id/skus", ProductController.getSKUsForProduct); get("/payment_intents/:id/status", PaymentController.getPaymentIntent); post("/payment_intents", PaymentController.createPaymentIntent); post("/payment_intents/:id/shipping_change", PaymentController.updatePaymentIntent); diff --git a/server/ruby/app.rb b/server/ruby/app.rb index 2bc3a783..809c59db 100644 --- a/server/ruby/app.rb +++ b/server/ruby/app.rb @@ -81,7 +81,7 @@ end end -get '/product/:product_id/skus' do +get '/products/:product_id/skus' do content_type 'application/json' skus = Inventory.list_skus(params['product_id']) skus.to_json