diff --git a/.github/dependabot.yml b/.github/dependabot.yml deleted file mode 100644 index 2a77014..0000000 --- a/.github/dependabot.yml +++ /dev/null @@ -1,22 +0,0 @@ -# To get started with Dependabot version updates, you'll need to specify which -# package ecosystems to update and where the package manifests are located. -# Please see the documentation for all configuration options: -# https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates - -version: 2 -updates: - - package-ecosystem: "github-actions" - directory: "/" - schedule: - interval: "weekly" - day: "saturday" - assignees: - - "lelledaniele" - - - package-ecosystem: "gomod" - directory: "/" - schedule: - interval: "weekly" - day: "saturday" - assignees: - - "lelledaniele" diff --git a/.github/hooks/pre-commit b/.github/hooks/pre-commit index b96f77b..c8a581e 100755 --- a/.github/hooks/pre-commit +++ b/.github/hooks/pre-commit @@ -2,18 +2,11 @@ go fmt ./... golint . -go test ./... -tags=unit -failfast -# shellcheck disable=SC2181 -if [ $? != 0 ] -then - echo "Committed code break unit tests" - exit 1 -fi -go test ./... -tags=stripe -failfast -config=ABS_PATH/config.json +go test ./... -failfast # shellcheck disable=SC2181 if [ $? != 0 ] then - echo "Committed code break Stripe tests" + echo "Committed code break tests" exit 1 fi diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml deleted file mode 100644 index c168c7d..0000000 --- a/.github/workflows/codeql-analysis.yml +++ /dev/null @@ -1,50 +0,0 @@ -name: "Code scanning - action" - -on: - push: - schedule: - - cron: '0 2 * * 1' - -jobs: - CodeQL-Build: - - runs-on: ubuntu-latest - - steps: - - name: Checkout repository - uses: actions/checkout@v2 - with: - # We must fetch at least the immediate parents so that if this is - # a pull request then we can checkout the head. - fetch-depth: 2 - - # If this run was triggered by a pull request event, then checkout - # the head of the pull request instead of the merge commit. - - run: git checkout HEAD^2 - if: ${{ github.event_name == 'pull_request' }} - - # Initializes the CodeQL tools for scanning. - - name: Initialize CodeQL - uses: github/codeql-action/init@v1 - # Override language selection by uncommenting this and choosing your languages - # with: - # languages: go, javascript, csharp, python, cpp, java - - # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). - # If this step fails, then you should remove it and run the build manually (see below) - - name: Autobuild - uses: github/codeql-action/autobuild@v1 - - # ℹī¸ Command-line programs to run using the OS shell. - # 📚 https://git.io/JvXDl - - # ✏ī¸ If the Autobuild fails above, remove it and uncomment the following three lines - # and modify them (or add more) to build your code if your project - # uses a compiled language - - #- run: | - # make bootstrap - # make release - - - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@v1 diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index f0caab2..266cbc1 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -7,17 +7,15 @@ jobs: runs-on: ubuntu-latest steps: - - name: Set up Go 1.14 - uses: actions/setup-go@v4.0.1 - with: - go-version: 1.14 - id: go - - name: Check out code into the Go module directory - uses: actions/checkout@v1 + uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v5 + id: go - name: Swagger - Installation - run: go get -u github.com/swaggo/swag/cmd/swag + run: go install github.com/swaggo/swag/cmd/swag@latest - name: Swagger - Init run: ~/go/bin/swag init @@ -35,11 +33,8 @@ jobs: cp config.json.dist config.json sed -i 's/pk_xxx/${{ secrets.STRIPE_PK }}/g; s/sk_xxx/${{ secrets.STRIPE_SK }}/g' config.json - - name: Tests - Unit - run: go test ./... -failfast -tags=unit - - - name: Tests - Stripe - run: go test ./... -failfast -tags=stripe -config=/home/runner/work/upaygo/upaygo/config.json + - name: Run Tests + run: go test ./... -failfast - name: Build run: go build -v . diff --git a/.gitignore b/.gitignore index e3501c6..8a42e39 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,6 @@ -/.idea -/vendor -/docs +.idea +vendor +.vscode -/upaygo.iml -/config.json +upaygo.iml +config.json diff --git a/.idx/.gitignore b/.idx/.gitignore new file mode 100644 index 0000000..96be05f --- /dev/null +++ b/.idx/.gitignore @@ -0,0 +1,2 @@ + +gc/ diff --git a/.idx/dev.nix b/.idx/dev.nix new file mode 100644 index 0000000..c035f9d --- /dev/null +++ b/.idx/dev.nix @@ -0,0 +1,37 @@ +{ pkgs, ... }: { + + # Which nixpkgs channel to use. + channel = "stable-23.11"; # or "unstable" + + # Use https://search.nixos.org/packages to find packages + packages = [ + pkgs.go + pkgs.docker + ]; + + # Sets environment variables in the workspace + env = { }; + + # Search for the extensions you want on https://open-vsx.org/ and use "publisher.id" + idx.extensions = [ + "open-vsx.go" + ]; + + idx.workspace.onCreate = { + go-tidy = "go mod tidy"; + go-vendor = "go mod vendor"; + }; + + idx.workspace.onStart = { + go-tidy = "go mod tidy"; + go-vendor = "go mod vendor"; + }; + + services.docker.enable = true; + + # Enable previews and customize configuration + idx.previews = { + enable = false; + previews = [ ]; + }; +} diff --git a/LICENSE b/LICENSE index c5306f5..502e2b3 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2019 Daniele Rostellato +Copyright (c) 2024 Daniele Rostellato Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index de4fe08..df8518b 100644 --- a/README.md +++ b/README.md @@ -60,8 +60,7 @@ go run main.go -config=config.json ## Tests ```bash -go test ./... -failfast -tags=unit -go test ./... -failfast -tags=stripe -config=ABS_PATH/config.json +go test ./... -failfast ``` ### APIs diff --git a/amount/amount_test.go b/amount/amount_test.go deleted file mode 100644 index 5a51a6a..0000000 --- a/amount/amount_test.go +++ /dev/null @@ -1,34 +0,0 @@ -// +build unit - -package appamount_test - -import ( - "testing" - - appamount "github.com/lelledaniele/upaygo/amount" - appcurrency "github.com/lelledaniele/upaygo/currency" -) - -func TestNew(t *testing.T) { - a := 4099 - c, _ := appcurrency.New("EUR") - got, e := appamount.New(a, c.GetISO4217()) - if e != nil { - t.Errorf("error during the amount creation: %v", e) - } - - if got.GetCurrency().GetISO4217() != c.GetISO4217() { - t.Errorf("error during the amount creation, currency value incorrect, got: %v want: %v", got.GetCurrency(), c) - } - - if got.GetAmount() != a { - t.Errorf("error during the amount creation, amount value incorrect, got: %v want: %v", got.GetAmount(), a) - } -} - -func TestNewWrongCurrency(t *testing.T) { - _, e := appamount.New(10, "I AM A WRONG CURRENCY") - if e == nil { - t.Error("new amount with wrong currency created") - } -} diff --git a/config/config_test.go b/config/config_test.go deleted file mode 100644 index 36a257a..0000000 --- a/config/config_test.go +++ /dev/null @@ -1,135 +0,0 @@ -// +build unit - -package appconfig_test - -import ( - "strings" - "testing" - - appconfig "github.com/lelledaniele/upaygo/config" -) - -const ( - confStripeWithDefault = ` -{ - "stripe": { - "api_keys": { - "EUR": { - "pk_key": "pk_EUR", - "sk_key": "sk_EUR" - }, - "default": { - "pk_key": "pk_DEFAULT", - "sk_key": "sk_DEFAULT" - } - } - } -} -` - confStripeWithoutDefault = ` -{ - "stripe": { - "api_keys": { - "EUR": { - "pk_key": "pk_EUR", - "sk_key": "sk_EUR" - } - } - } -} -` - confServer = ` -{ - "server": { - "protocol": "https://", - "domain": "localhost", - "port": "8080" - } -} -` -) - -func TestDefaultStripeAPIConfig(t *testing.T) { - e := appconfig.ImportConfig(strings.NewReader(confStripeWithDefault)) - if e != nil { - t.Errorf("error during the config import: %v", e) - } - - got, e := appconfig.GetStripeAPIConfigByCurrency("NOT_FOUND_CURRENCY") - if e != nil { - t.Errorf("error during the retrieve of Stripe API config by inexistent currency: %v", e) - } - - if got.GetPK() != "pk_DEFAULT" || got.GetSK() != "sk_DEFAULT" { - t.Errorf("Stripe API config for an inexistent currency does not return the default value") - } -} - -func TestWithoutDefaultStripeAPIConfig(t *testing.T) { - e := appconfig.ImportConfig(strings.NewReader(confStripeWithoutDefault)) - if e != nil { - t.Errorf("error during the config import: %v", e) - } - - _, e = appconfig.GetStripeAPIConfigByCurrency("NOT_FOUND_CURRENCY") - if e == nil { - t.Error("configuration without Stripe default API keys must return an error") - } -} - -func TestCurrencyStripeAPIConfig(t *testing.T) { - e := appconfig.ImportConfig(strings.NewReader(confStripeWithDefault)) - if e != nil { - t.Errorf("error during the config import: %v", e) - } - - got, e := appconfig.GetStripeAPIConfigByCurrency("EUR") - if e != nil { - t.Errorf("error during the retrieve of Stripe API config by EUR currency: %v", e) - } - - if got.GetPK() != "pk_EUR" || got.GetSK() != "sk_EUR" { - t.Errorf("incorrect Stripe API config for EUR currency, got %v and %v, want %v %v", got.GetPK(), got.GetSK(), "pk_EUR", "sk_EUR") - } -} - -func TestLowercaseCurrencyStripeAPIConfig(t *testing.T) { - e := appconfig.ImportConfig(strings.NewReader(confStripeWithDefault)) - if e != nil { - t.Errorf("error during the config import: %v", e) - } - - got, e := appconfig.GetStripeAPIConfigByCurrency("eur") - if e != nil { - t.Errorf("error during the retrieve of Stripe API config by eur currency: %v", e) - } - - if got.GetPK() != "pk_EUR" || got.GetSK() != "sk_EUR" { - t.Errorf("incorrect Stripe API config for eur currency, got %v and %v, want %v %v", got.GetPK(), got.GetSK(), "pk_EUR", "sk_EUR") - } -} - -func TestServerConfig(t *testing.T) { - e := appconfig.ImportConfig(strings.NewReader(confServer)) - if e != nil { - t.Errorf("error during the config import: %v", e) - } - - got := appconfig.GetServerConfig() - - if got.GetPort() != "8080" { - t.Errorf("incorrect server config PORT, got: %v want: %v", got.GetPort(), "8080") - } - - if got.GetDomain() != "localhost" { - t.Errorf("incorrect server config domain, got: %v want: %v", got.GetDomain(), "localhost") - } - - if got.GetProtocol() != "https://" { - t.Errorf("incorrect server config protocol, got: %v want: %v", got.GetProtocol(), "https://") - } - - if got.GetURI() != "https://localhost:8080" { - t.Errorf("incorrect server config URI, got: %v want: %v", got.GetURI(), "https://localhost:8080") - } -} diff --git a/controller/rest/intent/cancel/restintentcancel_integration_test.go b/controller/rest/intent/cancel/restintentcancel_integration_test.go deleted file mode 100644 index fb57230..0000000 --- a/controller/rest/intent/cancel/restintentcancel_integration_test.go +++ /dev/null @@ -1,125 +0,0 @@ -// +build stripe - -package apprestintentcancel_test - -import ( - "encoding/json" - "flag" - "fmt" - "io/ioutil" - "net/http" - "net/http/httptest" - "os" - "strings" - "testing" - - appconfig "github.com/lelledaniele/upaygo/config" - apprestintentcancel "github.com/lelledaniele/upaygo/controller/rest/intent/cancel" - appcurrency "github.com/lelledaniele/upaygo/currency" - - "github.com/gorilla/mux" - "github.com/stripe/stripe-go" - "github.com/stripe/stripe-go/paymentintent" -) - -const ( - errorRestCreateIntent = "cancel intent controller failed: %v" -) - -type responseIntent struct { - IntentGatewayReference string `json:"gateway_reference"` - Status responseStatus `json:"status"` -} - -type responseStatus struct { - R string `json:"gateway_reference"` -} - -func TestMain(m *testing.M) { - var fcp string - - flag.StringVar(&fcp, "config", "", "Provide config file as an absolute path") - flag.Parse() - - if fcp == "" { - fmt.Print("Integration Stripe test needs the config file absolute path as flag -config") - os.Exit(1) - } - - fc, e := os.Open(fcp) - if e != nil { - fmt.Printf("Impossible to get configuration file: %v\n", e) - os.Exit(1) - } - defer fc.Close() - - e = appconfig.ImportConfig(fc) - if e != nil { - fmt.Printf("Error durring file config import: %v", e) - os.Exit(1) - } - - os.Exit(m.Run()) -} - -func createTestIntent() (string, error) { - cur, _ := appcurrency.New("EUR") - am := int64(4567) - pip := &stripe.PaymentIntentParams{ - Amount: stripe.Int64(am), - Currency: stripe.String(cur.GetISO4217()), - PaymentMethod: stripe.String("pm_card_visa"), - SetupFutureUsage: stripe.String("off_session"), - ConfirmationMethod: stripe.String("automatic"), - Confirm: stripe.Bool(true), - CaptureMethod: stripe.String("manual"), - } - - sck, _ := appconfig.GetStripeAPIConfigByCurrency(cur.GetISO4217()) - stripe.Key = sck.GetSK() - - intent, e := paymentintent.New(pip) - if e != nil { - return "", fmt.Errorf("impossible to create a new payment intent for testing: %v", e) - } - - return intent.ID, e -} - -// Test a create intent request -func Test(t *testing.T) { - intentID, e := createTestIntent() - if e != nil { - t.Error(e.Error()) - } - - w := httptest.NewRecorder() - req := httptest.NewRequest(http.MethodPost, "http://example.com", strings.NewReader("currency=EUR")) - req.Header.Set("Content-Type", "application/x-www-form-urlencoded") - req = mux.SetURLVars(req, map[string]string{"id": intentID}) - - apprestintentcancel.Handler(w, req) - - res := w.Result() - resBody, e := ioutil.ReadAll(res.Body) - if e != nil { - t.Errorf(errorRestCreateIntent, e) - } - defer res.Body.Close() - - var resI responseIntent - e = json.Unmarshal(resBody, &resI) - if e != nil { - t.Errorf(errorRestCreateIntent, e) - } - - if resI.IntentGatewayReference == "" { - t.Errorf(errorRestCreateIntent, "the body response does not have the gateway reference") - } - - if resI.Status.R != "canceled" { - t.Errorf(errorRestCreateIntent, "the body response does not have the status 'canceled'") - } - - _, _ = paymentintent.Cancel(intentID, nil) -} diff --git a/controller/rest/intent/capture/restintentcapture_integration_test.go b/controller/rest/intent/capture/restintentcapture_integration_test.go deleted file mode 100644 index e26c197..0000000 --- a/controller/rest/intent/capture/restintentcapture_integration_test.go +++ /dev/null @@ -1,125 +0,0 @@ -// +build stripe - -package apprestintentcapture_test - -import ( - "encoding/json" - "flag" - "fmt" - "io/ioutil" - "net/http" - "net/http/httptest" - "os" - "strings" - "testing" - - appconfig "github.com/lelledaniele/upaygo/config" - apprestintentcapture "github.com/lelledaniele/upaygo/controller/rest/intent/capture" - appcurrency "github.com/lelledaniele/upaygo/currency" - - "github.com/gorilla/mux" - "github.com/stripe/stripe-go" - "github.com/stripe/stripe-go/paymentintent" -) - -const ( - errorRestCreateIntent = "capture intent controller failed: %v" -) - -type responseIntent struct { - IntentGatewayReference string `json:"gateway_reference"` - Status responseStatus `json:"status"` -} - -type responseStatus struct { - R string `json:"gateway_reference"` -} - -func TestMain(m *testing.M) { - var fcp string - - flag.StringVar(&fcp, "config", "", "Provide config file as an absolute path") - flag.Parse() - - if fcp == "" { - fmt.Print("Integration Stripe test needs the config file absolute path as flag -config") - os.Exit(1) - } - - fc, e := os.Open(fcp) - if e != nil { - fmt.Printf("Impossible to get configuration file: %v\n", e) - os.Exit(1) - } - defer fc.Close() - - e = appconfig.ImportConfig(fc) - if e != nil { - fmt.Printf("Error durring file config import: %v", e) - os.Exit(1) - } - - os.Exit(m.Run()) -} - -func createTestIntent() (string, error) { - cur, _ := appcurrency.New("EUR") - am := int64(1179) - pip := &stripe.PaymentIntentParams{ - Amount: stripe.Int64(am), - Currency: stripe.String(cur.GetISO4217()), - PaymentMethod: stripe.String("pm_card_visa"), - SetupFutureUsage: stripe.String("off_session"), - ConfirmationMethod: stripe.String("automatic"), - Confirm: stripe.Bool(true), - CaptureMethod: stripe.String("manual"), - } - - sck, _ := appconfig.GetStripeAPIConfigByCurrency(cur.GetISO4217()) - stripe.Key = sck.GetSK() - - intent, e := paymentintent.New(pip) - if e != nil { - return "", fmt.Errorf("impossible to create a new payment intent for testing: %v", e) - } - - return intent.ID, e -} - -// Test a create intent request -func Test(t *testing.T) { - intentID, e := createTestIntent() - if e != nil { - t.Error(e.Error()) - } - - w := httptest.NewRecorder() - req := httptest.NewRequest(http.MethodPost, "http://example.com", strings.NewReader("currency=EUR")) - req.Header.Set("Content-Type", "application/x-www-form-urlencoded") - req = mux.SetURLVars(req, map[string]string{"id": intentID}) - - apprestintentcapture.Handler(w, req) - - res := w.Result() - resBody, e := ioutil.ReadAll(res.Body) - if e != nil { - t.Errorf(errorRestCreateIntent, e) - } - defer res.Body.Close() - - var resI responseIntent - e = json.Unmarshal(resBody, &resI) - if e != nil { - t.Errorf(errorRestCreateIntent, e) - } - - if resI.IntentGatewayReference == "" { - t.Errorf(errorRestCreateIntent, "the body response does not have the gateway reference") - } - - if resI.Status.R != "succeeded" { - t.Errorf(errorRestCreateIntent, "the body response does not have the status 'succeeded'") - } - - _, _ = paymentintent.Cancel(intentID, nil) -} diff --git a/controller/rest/intent/confirm/restintentconfirm_integration_test.go b/controller/rest/intent/confirm/restintentconfirm_integration_test.go deleted file mode 100644 index 29ac46b..0000000 --- a/controller/rest/intent/confirm/restintentconfirm_integration_test.go +++ /dev/null @@ -1,124 +0,0 @@ -// +build stripe - -package apprestintentconfirm_test - -import ( - "encoding/json" - "flag" - "fmt" - "io/ioutil" - "net/http" - "net/http/httptest" - "os" - "strings" - "testing" - - appconfig "github.com/lelledaniele/upaygo/config" - apprestintentconfirm "github.com/lelledaniele/upaygo/controller/rest/intent/confirm" - appcurrency "github.com/lelledaniele/upaygo/currency" - - "github.com/gorilla/mux" - "github.com/stripe/stripe-go" - "github.com/stripe/stripe-go/paymentintent" -) - -const ( - errorRestCreateIntent = "confirm intent controller failed: %v" -) - -type responseIntent struct { - IntentGatewayReference string `json:"gateway_reference"` - Status responseStatus `json:"status"` -} - -type responseStatus struct { - R string `json:"gateway_reference"` -} - -func TestMain(m *testing.M) { - var fcp string - - flag.StringVar(&fcp, "config", "", "Provide config file as an absolute path") - flag.Parse() - - if fcp == "" { - fmt.Print("Integration Stripe test needs the config file absolute path as flag -config") - os.Exit(1) - } - - fc, e := os.Open(fcp) - if e != nil { - fmt.Printf("Impossible to get configuration file: %v\n", e) - os.Exit(1) - } - defer fc.Close() - - e = appconfig.ImportConfig(fc) - if e != nil { - fmt.Printf("Error durring file config import: %v", e) - os.Exit(1) - } - - os.Exit(m.Run()) -} - -func createTestIntent() (string, error) { - cur, _ := appcurrency.New("EUR") - am := int64(4567) - pip := &stripe.PaymentIntentParams{ - Amount: stripe.Int64(am), - Currency: stripe.String(cur.GetISO4217()), - PaymentMethod: stripe.String("pm_card_visa"), - SetupFutureUsage: stripe.String("off_session"), - ConfirmationMethod: stripe.String("manual"), - CaptureMethod: stripe.String("manual"), - } - - sck, _ := appconfig.GetStripeAPIConfigByCurrency(cur.GetISO4217()) - stripe.Key = sck.GetSK() - - intent, e := paymentintent.New(pip) - if e != nil { - return "", fmt.Errorf("impossible to create a new payment intent for testing: %v", e) - } - - return intent.ID, e -} - -// Test a create intent request -func Test(t *testing.T) { - intentID, e := createTestIntent() - if e != nil { - t.Error(e.Error()) - } - - w := httptest.NewRecorder() - req := httptest.NewRequest(http.MethodPost, "http://example.com", strings.NewReader("currency=EUR")) - req.Header.Set("Content-Type", "application/x-www-form-urlencoded") - req = mux.SetURLVars(req, map[string]string{"id": intentID}) - - apprestintentconfirm.Handler(w, req) - - res := w.Result() - resBody, e := ioutil.ReadAll(res.Body) - if e != nil { - t.Errorf(errorRestCreateIntent, e) - } - defer res.Body.Close() - - var resI responseIntent - e = json.Unmarshal(resBody, &resI) - if e != nil { - t.Errorf(errorRestCreateIntent, e) - } - - if resI.IntentGatewayReference == "" { - t.Errorf(errorRestCreateIntent, "the body response does not have the gateway reference") - } - - if resI.Status.R != "requires_capture" { - t.Errorf(errorRestCreateIntent, "the body response does not have the status as 'requires_capture'") - } - - _, _ = paymentintent.Cancel(intentID, nil) -} diff --git a/controller/rest/intent/create/restintentcreate_integration_test.go b/controller/rest/intent/create/restintentcreate_integration_test.go deleted file mode 100644 index 09faf5c..0000000 --- a/controller/rest/intent/create/restintentcreate_integration_test.go +++ /dev/null @@ -1,131 +0,0 @@ -// +build stripe - -package apprestintentcreate_test - -import ( - "encoding/json" - "flag" - "fmt" - "io/ioutil" - "net/http" - "net/http/httptest" - "os" - "strings" - "testing" - - "github.com/stripe/stripe-go/customer" - - appconfig "github.com/lelledaniele/upaygo/config" - apprestintentcreate "github.com/lelledaniele/upaygo/controller/rest/intent/create" - appcurrency "github.com/lelledaniele/upaygo/currency" - appcustomer "github.com/lelledaniele/upaygo/customer" -) - -const ( - errorRestCreateIntent = "create intent controller failed: %v" -) - -type responseIntent struct { - IntentGatewayReference string `json:"gateway_reference"` - Customer responseCustomer `json:"customer"` -} - -type responseCustomer struct { - R string `json:"gateway_reference"` -} - -func TestMain(m *testing.M) { - var fcp string - - flag.StringVar(&fcp, "config", "", "Provide config file as an absolute path") - flag.Parse() - - if fcp == "" { - fmt.Print("Integration Stripe test needs the config file absolute path as flag -config") - os.Exit(1) - } - - fc, e := os.Open(fcp) - if e != nil { - fmt.Printf("Impossible to get configuration file: %v\n", e) - os.Exit(1) - } - defer fc.Close() - - e = appconfig.ImportConfig(fc) - if e != nil { - fmt.Printf("Error durring file config import: %v", e) - os.Exit(1) - } - - os.Exit(m.Run()) -} - -// Test a create intent request -func Test(t *testing.T) { - var resI responseIntent - - c, _ := appcurrency.New("EUR") - cus, e := appcustomer.NewStripe("email@email.com", c) - if e != nil { - t.Errorf(errorRestCreateIntent, e) - } - - a, ps, w := 7777, "pm_card_visa", httptest.NewRecorder() - p := fmt.Sprintf("currency=%v&amount=%v&payment_source=%v&customer_reference=%v", c.GetISO4217(), a, ps, cus.GetGatewayReference()) - req := httptest.NewRequest("POST", "http://example.com", strings.NewReader(p)) - req.Header.Set("Content-Type", "application/x-www-form-urlencoded") - - apprestintentcreate.Handler(w, req) - - res := w.Result() - resBody, e := ioutil.ReadAll(res.Body) - if e != nil { - t.Errorf(errorRestCreateIntent, e) - } - defer res.Body.Close() - - e = json.Unmarshal(resBody, &resI) - if e != nil { - t.Errorf(errorRestCreateIntent, e) - } - - if resI.IntentGatewayReference == "" { - t.Errorf(errorRestCreateIntent, "the body response does not have the gateway reference") - } - - if resI.Customer.R == "" { - t.Errorf(errorRestCreateIntent, "the body response does not have the customer reference") - } - - _, _ = customer.Del(cus.GetGatewayReference(), nil) -} - -// Test a create intent request without customer -func TestWithoutCustomer(t *testing.T) { - var resI responseIntent - - c, a, ps, w := "EUR", 9999, "pm_card_visa", httptest.NewRecorder() - p := fmt.Sprintf("currency=%v&amount=%v&payment_source=%v", c, a, ps) - - req := httptest.NewRequest(http.MethodPost, "http://example.com", strings.NewReader(p)) - req.Header.Set("Content-Type", "application/x-www-form-urlencoded") - - apprestintentcreate.Handler(w, req) - - res := w.Result() - resBody, e := ioutil.ReadAll(res.Body) - _ = res.Body.Close() - if e != nil { - t.Errorf(errorRestCreateIntent, e) - } - - e = json.Unmarshal(resBody, &resI) - if e != nil { - t.Errorf(errorRestCreateIntent, e) - } - - if resI.IntentGatewayReference == "" { - t.Errorf(errorRestCreateIntent, "the body response does not have the gateway reference") - } -} diff --git a/controller/rest/intent/get/restintentget_integration_test.go b/controller/rest/intent/get/restintentget_integration_test.go deleted file mode 100644 index c1422b9..0000000 --- a/controller/rest/intent/get/restintentget_integration_test.go +++ /dev/null @@ -1,124 +0,0 @@ -// +build stripe - -package apprestintentget_test - -import ( - "encoding/json" - "flag" - "fmt" - "io/ioutil" - "net/http" - "net/http/httptest" - "os" - "testing" - - apprestintentget "github.com/lelledaniele/upaygo/controller/rest/intent/get" - - appconfig "github.com/lelledaniele/upaygo/config" - appcurrency "github.com/lelledaniele/upaygo/currency" - - "github.com/gorilla/mux" - "github.com/stripe/stripe-go" - "github.com/stripe/stripe-go/paymentintent" -) - -const ( - errorRestCreateIntent = "cancel intent controller failed: %v" -) - -type responseIntent struct { - IntentGatewayReference string `json:"gateway_reference"` - Status responseStatus `json:"status"` -} - -type responseStatus struct { - R string `json:"gateway_reference"` -} - -func TestMain(m *testing.M) { - var fcp string - - flag.StringVar(&fcp, "config", "", "Provide config file as an absolute path") - flag.Parse() - - if fcp == "" { - fmt.Print("Integration Stripe test needs the config file absolute path as flag -config") - os.Exit(1) - } - - fc, e := os.Open(fcp) - if e != nil { - fmt.Printf("Impossible to get configuration file: %v\n", e) - os.Exit(1) - } - defer fc.Close() - - e = appconfig.ImportConfig(fc) - if e != nil { - fmt.Printf("Error durring file config import: %v", e) - os.Exit(1) - } - - os.Exit(m.Run()) -} - -func createTestIntent() (string, error) { - cur, _ := appcurrency.New("EUR") - am := int64(4567) - pip := &stripe.PaymentIntentParams{ - Amount: stripe.Int64(am), - Currency: stripe.String(cur.GetISO4217()), - PaymentMethod: stripe.String("pm_card_visa"), - SetupFutureUsage: stripe.String("off_session"), - ConfirmationMethod: stripe.String("automatic"), - Confirm: stripe.Bool(true), - CaptureMethod: stripe.String("manual"), - } - - sck, _ := appconfig.GetStripeAPIConfigByCurrency(cur.GetISO4217()) - stripe.Key = sck.GetSK() - - intent, e := paymentintent.New(pip) - if e != nil { - return "", fmt.Errorf("impossible to create a new payment intent for testing: %v", e) - } - - return intent.ID, e -} - -// Test a create intent request -func Test(t *testing.T) { - intentID, e := createTestIntent() - if e != nil { - t.Error(e.Error()) - } - - w := httptest.NewRecorder() - req := httptest.NewRequest(http.MethodGet, "http://example.com", nil) - req = mux.SetURLVars(req, map[string]string{"id": intentID}) - - q := req.URL.Query() - q.Add("currency", "EUR") - req.URL.RawQuery = q.Encode() - - apprestintentget.Handler(w, req) - - res := w.Result() - resBody, e := ioutil.ReadAll(res.Body) - if e != nil { - t.Errorf(errorRestCreateIntent, e) - } - defer res.Body.Close() - - var resI responseIntent - e = json.Unmarshal(resBody, &resI) - if e != nil { - t.Errorf(errorRestCreateIntent, e) - } - - if resI.IntentGatewayReference == "" { - t.Errorf(errorRestCreateIntent, "the body response does not have the gateway reference") - } - - _, _ = paymentintent.Cancel(intentID, nil) -} diff --git a/currency/currency_test.go b/currency/currency_test.go deleted file mode 100644 index c72e8e3..0000000 --- a/currency/currency_test.go +++ /dev/null @@ -1,30 +0,0 @@ -// +build unit - -package appcurrency_test - -import ( - "strings" - "testing" - - appcurrency "github.com/lelledaniele/upaygo/currency" -) - -func TestNew(t *testing.T) { - cs := "EUR" - c, e := appcurrency.New(strings.ToLower(cs)) - if e != nil { - t.Errorf("error during the appcurrency.New func: %v", e) - } - - if c.GetISO4217() != cs { - t.Errorf("appcurrency.New func returns a currency ISO4217 incorrect: got: %v want %v", c.GetISO4217(), cs) - } -} - -func TestNewWithWrongCurrency(t *testing.T) { - _, e := appcurrency.New("I AM A WRONG CURRENCY") - - if e == nil { - t.Error("No error during appcurrency creation with a wrong ISO4217") - } -} diff --git a/customer/customer_test.go b/customer/customer_test.go deleted file mode 100644 index f62c845..0000000 --- a/customer/customer_test.go +++ /dev/null @@ -1,22 +0,0 @@ -// +build unit - -package appcustomer_test - -import ( - "testing" - - appcustomer "github.com/lelledaniele/upaygo/customer" -) - -func TestNew(t *testing.T) { - ref, email := "GATEWAY REFERENCE", "email@email.com" - got := appcustomer.New(ref, email) - - if got.GetGatewayReference() != ref { - t.Errorf("The new customer.gateway_reference is incorrect, got: %v want %v", got.GetGatewayReference(), ref) - } - - if got.GetEmail() != email { - t.Errorf("The new customer.email is incorrect, got: %v want %v", got.GetEmail(), email) - } -} diff --git a/customer/customerstripe.go b/customer/customerstripe.go index 59eb66a..ba9b245 100644 --- a/customer/customerstripe.go +++ b/customer/customerstripe.go @@ -5,12 +5,12 @@ import ( apperror "github.com/lelledaniele/upaygo/error" - "github.com/stripe/stripe-go/customer" + "github.com/stripe/stripe-go/v76/customer" appconfig "github.com/lelledaniele/upaygo/config" appcurrency "github.com/lelledaniele/upaygo/currency" - "github.com/stripe/stripe-go" + "github.com/stripe/stripe-go/v76" ) func NewStripe(email string, ac appcurrency.Currency) (Customer, error) { diff --git a/customer/customerstripe_integration_test.go b/customer/customerstripe_integration_test.go deleted file mode 100644 index a0176db..0000000 --- a/customer/customerstripe_integration_test.go +++ /dev/null @@ -1,64 +0,0 @@ -// +build stripe - -package appcustomer_test - -import ( - "flag" - "fmt" - "os" - "testing" - - "github.com/stripe/stripe-go/customer" - - appcurrency "github.com/lelledaniele/upaygo/currency" - - appconfig "github.com/lelledaniele/upaygo/config" - appcustomer "github.com/lelledaniele/upaygo/customer" -) - -func TestMain(m *testing.M) { - var fcp string - - flag.StringVar(&fcp, "config", "", "Provide config file as an absolute path") - flag.Parse() - - if fcp == "" { - fmt.Print("Integration Stripe test needs the config file absolute path as flag -config") - os.Exit(1) - } - - fc, e := os.Open(fcp) - if e != nil { - fmt.Printf("Impossible to get configuration file: %v\n", e) - os.Exit(1) - } - defer fc.Close() - - e = appconfig.ImportConfig(fc) - if e != nil { - fmt.Printf("Error durring file config import: %v", e) - os.Exit(1) - } - - os.Exit(m.Run()) -} - -func TestNewStripe(t *testing.T) { - email := "email@email.com" - c, _ := appcurrency.New("EUR") - - got, e := appcustomer.NewStripe(email, c) - if e != nil { - t.Errorf("error during the appcustomer creation with Stripe: %v", e) - } - - if got.GetGatewayReference() == "" { - t.Errorf("The new customer.gateway_reference is empty, got: %v", got.GetGatewayReference()) - } - - if got.GetEmail() != email { - t.Errorf("The new customer.email is incorrect, got: %v want %v", got.GetEmail(), email) - } - - _, _ = customer.Del(got.GetGatewayReference(), nil) -} diff --git a/docs/docs.go b/docs/docs.go new file mode 100644 index 0000000..bafc180 --- /dev/null +++ b/docs/docs.go @@ -0,0 +1,348 @@ +// Package docs Code generated by swaggo/swag. DO NOT EDIT +package docs + +import "github.com/swaggo/swag" + +const docTemplate = `{ + "schemes": {{ marshal .Schemes }}, + "swagger": "2.0", + "info": { + "description": "{{escape .Description}}", + "title": "{{.Title}}", + "contact": {}, + "license": { + "name": "MIT" + }, + "version": "{{.Version}}" + }, + "host": "{{.Host}}", + "basePath": "{{.BasePath}}", + "paths": { + "/payment_intents": { + "post": { + "description": "Create an unconfirmed and manual intent", + "consumes": [ + "application/x-www-form-urlencoded" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Intent" + ], + "summary": "Create an intent", + "parameters": [ + { + "type": "string", + "description": "Intent's currency", + "name": "currency", + "in": "formData", + "required": true + }, + { + "type": "integer", + "description": "Intent's amount", + "name": "amount", + "in": "formData", + "required": true + }, + { + "type": "string", + "description": "Intent's payment source", + "name": "payment_source", + "in": "formData", + "required": true + }, + { + "type": "string", + "description": "Intent's customer reference", + "name": "customer_reference", + "in": "formData" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "interface" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/apperror.RESTError" + } + }, + "405": { + "description": "Method Not Allowed", + "schema": { + "$ref": "#/definitions/apperror.RESTError" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/apperror.RESTError" + } + } + } + } + }, + "/payment_intents/{id}": { + "get": { + "description": "Get an existing intent", + "consumes": [ + "application/x-www-form-urlencoded" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Intent" + ], + "summary": "Get an intent", + "parameters": [ + { + "type": "string", + "description": "Intent's ID", + "name": "id", + "in": "path", + "required": true + }, + { + "type": "string", + "description": "Intent's currency", + "name": "currency", + "in": "formData", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "interface" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/apperror.RESTError" + } + }, + "405": { + "description": "Method Not Allowed", + "schema": { + "$ref": "#/definitions/apperror.RESTError" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/apperror.RESTError" + } + } + } + } + }, + "/payment_intents/{id}/cancel": { + "post": { + "description": "Cancel an confirmed intent", + "consumes": [ + "application/x-www-form-urlencoded" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Intent" + ], + "summary": "Cancel an intent", + "parameters": [ + { + "type": "string", + "description": "Intent's ID", + "name": "id", + "in": "path", + "required": true + }, + { + "type": "string", + "description": "Intent's currency", + "name": "currency", + "in": "formData", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "interface" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/apperror.RESTError" + } + }, + "405": { + "description": "Method Not Allowed", + "schema": { + "$ref": "#/definitions/apperror.RESTError" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/apperror.RESTError" + } + } + } + } + }, + "/payment_intents/{id}/capture": { + "post": { + "description": "Capture an confirmed intent", + "consumes": [ + "application/x-www-form-urlencoded" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Intent" + ], + "summary": "Capture an intent", + "parameters": [ + { + "type": "string", + "description": "Intent's ID", + "name": "id", + "in": "path", + "required": true + }, + { + "type": "string", + "description": "Intent's currency", + "name": "currency", + "in": "formData", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "interface" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/apperror.RESTError" + } + }, + "405": { + "description": "Method Not Allowed", + "schema": { + "$ref": "#/definitions/apperror.RESTError" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/apperror.RESTError" + } + } + } + } + }, + "/payment_intents/{id}/confirm": { + "post": { + "description": "Confirm an unconfirmed intent", + "consumes": [ + "application/x-www-form-urlencoded" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Intent" + ], + "summary": "Confirm an intent", + "parameters": [ + { + "type": "string", + "description": "Intent's ID", + "name": "id", + "in": "path", + "required": true + }, + { + "type": "string", + "description": "Intent's currency", + "name": "currency", + "in": "formData", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "interface" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/apperror.RESTError" + } + }, + "405": { + "description": "Method Not Allowed", + "schema": { + "$ref": "#/definitions/apperror.RESTError" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/apperror.RESTError" + } + } + } + } + } + }, + "definitions": { + "apperror.RESTError": { + "type": "object", + "properties": { + "error": { + "type": "string" + } + } + } + } +}` + +// SwaggerInfo holds exported Swagger Info so clients can modify it +var SwaggerInfo = &swag.Spec{ + Version: "1.0.0", + Host: "", + BasePath: "", + Schemes: []string{}, + Title: "uPayment in GO", + Description: "Microservice to manage payment", + InfoInstanceName: "swagger", + SwaggerTemplate: docTemplate, + LeftDelim: "{{", + RightDelim: "}}", +} + +func init() { + swag.Register(SwaggerInfo.InstanceName(), SwaggerInfo) +} diff --git a/docs/swagger.json b/docs/swagger.json new file mode 100644 index 0000000..0c2fa36 --- /dev/null +++ b/docs/swagger.json @@ -0,0 +1,322 @@ +{ + "swagger": "2.0", + "info": { + "description": "Microservice to manage payment", + "title": "uPayment in GO", + "contact": {}, + "license": { + "name": "MIT" + }, + "version": "1.0.0" + }, + "paths": { + "/payment_intents": { + "post": { + "description": "Create an unconfirmed and manual intent", + "consumes": [ + "application/x-www-form-urlencoded" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Intent" + ], + "summary": "Create an intent", + "parameters": [ + { + "type": "string", + "description": "Intent's currency", + "name": "currency", + "in": "formData", + "required": true + }, + { + "type": "integer", + "description": "Intent's amount", + "name": "amount", + "in": "formData", + "required": true + }, + { + "type": "string", + "description": "Intent's payment source", + "name": "payment_source", + "in": "formData", + "required": true + }, + { + "type": "string", + "description": "Intent's customer reference", + "name": "customer_reference", + "in": "formData" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "interface" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/apperror.RESTError" + } + }, + "405": { + "description": "Method Not Allowed", + "schema": { + "$ref": "#/definitions/apperror.RESTError" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/apperror.RESTError" + } + } + } + } + }, + "/payment_intents/{id}": { + "get": { + "description": "Get an existing intent", + "consumes": [ + "application/x-www-form-urlencoded" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Intent" + ], + "summary": "Get an intent", + "parameters": [ + { + "type": "string", + "description": "Intent's ID", + "name": "id", + "in": "path", + "required": true + }, + { + "type": "string", + "description": "Intent's currency", + "name": "currency", + "in": "formData", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "interface" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/apperror.RESTError" + } + }, + "405": { + "description": "Method Not Allowed", + "schema": { + "$ref": "#/definitions/apperror.RESTError" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/apperror.RESTError" + } + } + } + } + }, + "/payment_intents/{id}/cancel": { + "post": { + "description": "Cancel an confirmed intent", + "consumes": [ + "application/x-www-form-urlencoded" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Intent" + ], + "summary": "Cancel an intent", + "parameters": [ + { + "type": "string", + "description": "Intent's ID", + "name": "id", + "in": "path", + "required": true + }, + { + "type": "string", + "description": "Intent's currency", + "name": "currency", + "in": "formData", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "interface" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/apperror.RESTError" + } + }, + "405": { + "description": "Method Not Allowed", + "schema": { + "$ref": "#/definitions/apperror.RESTError" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/apperror.RESTError" + } + } + } + } + }, + "/payment_intents/{id}/capture": { + "post": { + "description": "Capture an confirmed intent", + "consumes": [ + "application/x-www-form-urlencoded" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Intent" + ], + "summary": "Capture an intent", + "parameters": [ + { + "type": "string", + "description": "Intent's ID", + "name": "id", + "in": "path", + "required": true + }, + { + "type": "string", + "description": "Intent's currency", + "name": "currency", + "in": "formData", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "interface" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/apperror.RESTError" + } + }, + "405": { + "description": "Method Not Allowed", + "schema": { + "$ref": "#/definitions/apperror.RESTError" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/apperror.RESTError" + } + } + } + } + }, + "/payment_intents/{id}/confirm": { + "post": { + "description": "Confirm an unconfirmed intent", + "consumes": [ + "application/x-www-form-urlencoded" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Intent" + ], + "summary": "Confirm an intent", + "parameters": [ + { + "type": "string", + "description": "Intent's ID", + "name": "id", + "in": "path", + "required": true + }, + { + "type": "string", + "description": "Intent's currency", + "name": "currency", + "in": "formData", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "interface" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/apperror.RESTError" + } + }, + "405": { + "description": "Method Not Allowed", + "schema": { + "$ref": "#/definitions/apperror.RESTError" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/apperror.RESTError" + } + } + } + } + } + }, + "definitions": { + "apperror.RESTError": { + "type": "object", + "properties": { + "error": { + "type": "string" + } + } + } + } +} \ No newline at end of file diff --git a/docs/swagger.yaml b/docs/swagger.yaml new file mode 100644 index 0000000..40f4d4b --- /dev/null +++ b/docs/swagger.yaml @@ -0,0 +1,214 @@ +definitions: + apperror.RESTError: + properties: + error: + type: string + type: object +info: + contact: {} + description: Microservice to manage payment + license: + name: MIT + title: uPayment in GO + version: 1.0.0 +paths: + /payment_intents: + post: + consumes: + - application/x-www-form-urlencoded + description: Create an unconfirmed and manual intent + parameters: + - description: Intent's currency + in: formData + name: currency + required: true + type: string + - description: Intent's amount + in: formData + name: amount + required: true + type: integer + - description: Intent's payment source + in: formData + name: payment_source + required: true + type: string + - description: Intent's customer reference + in: formData + name: customer_reference + type: string + produces: + - application/json + responses: + "200": + description: OK + schema: + type: interface + "400": + description: Bad Request + schema: + $ref: '#/definitions/apperror.RESTError' + "405": + description: Method Not Allowed + schema: + $ref: '#/definitions/apperror.RESTError' + "500": + description: Internal Server Error + schema: + $ref: '#/definitions/apperror.RESTError' + summary: Create an intent + tags: + - Intent + /payment_intents/{id}: + get: + consumes: + - application/x-www-form-urlencoded + description: Get an existing intent + parameters: + - description: Intent's ID + in: path + name: id + required: true + type: string + - description: Intent's currency + in: formData + name: currency + required: true + type: string + produces: + - application/json + responses: + "200": + description: OK + schema: + type: interface + "400": + description: Bad Request + schema: + $ref: '#/definitions/apperror.RESTError' + "405": + description: Method Not Allowed + schema: + $ref: '#/definitions/apperror.RESTError' + "500": + description: Internal Server Error + schema: + $ref: '#/definitions/apperror.RESTError' + summary: Get an intent + tags: + - Intent + /payment_intents/{id}/cancel: + post: + consumes: + - application/x-www-form-urlencoded + description: Cancel an confirmed intent + parameters: + - description: Intent's ID + in: path + name: id + required: true + type: string + - description: Intent's currency + in: formData + name: currency + required: true + type: string + produces: + - application/json + responses: + "200": + description: OK + schema: + type: interface + "400": + description: Bad Request + schema: + $ref: '#/definitions/apperror.RESTError' + "405": + description: Method Not Allowed + schema: + $ref: '#/definitions/apperror.RESTError' + "500": + description: Internal Server Error + schema: + $ref: '#/definitions/apperror.RESTError' + summary: Cancel an intent + tags: + - Intent + /payment_intents/{id}/capture: + post: + consumes: + - application/x-www-form-urlencoded + description: Capture an confirmed intent + parameters: + - description: Intent's ID + in: path + name: id + required: true + type: string + - description: Intent's currency + in: formData + name: currency + required: true + type: string + produces: + - application/json + responses: + "200": + description: OK + schema: + type: interface + "400": + description: Bad Request + schema: + $ref: '#/definitions/apperror.RESTError' + "405": + description: Method Not Allowed + schema: + $ref: '#/definitions/apperror.RESTError' + "500": + description: Internal Server Error + schema: + $ref: '#/definitions/apperror.RESTError' + summary: Capture an intent + tags: + - Intent + /payment_intents/{id}/confirm: + post: + consumes: + - application/x-www-form-urlencoded + description: Confirm an unconfirmed intent + parameters: + - description: Intent's ID + in: path + name: id + required: true + type: string + - description: Intent's currency + in: formData + name: currency + required: true + type: string + produces: + - application/json + responses: + "200": + description: OK + schema: + type: interface + "400": + description: Bad Request + schema: + $ref: '#/definitions/apperror.RESTError' + "405": + description: Method Not Allowed + schema: + $ref: '#/definitions/apperror.RESTError' + "500": + description: Internal Server Error + schema: + $ref: '#/definitions/apperror.RESTError' + summary: Confirm an intent + tags: + - Intent +swagger: "2.0" diff --git a/error/stripe.go b/error/stripe.go index ab34797..bc7ea9e 100644 --- a/error/stripe.go +++ b/error/stripe.go @@ -3,7 +3,7 @@ package apperror import ( "encoding/json" - "github.com/stripe/stripe-go" + "github.com/stripe/stripe-go/v76" ) // Stripe returns a built-in error diff --git a/error/stripe_test.go b/error/stripe_test.go deleted file mode 100644 index 537f572..0000000 --- a/error/stripe_test.go +++ /dev/null @@ -1,22 +0,0 @@ -// +build unit - -package apperror_test - -import ( - "errors" - "testing" - - apperror "github.com/lelledaniele/upaygo/error" -) - -func TestGetStripeErrorMessage(t *testing.T) { - es := errors.New("{\"status\":401,\"message\":\"Invalid API Key provided: sk_xxx\",\"type\":\"invalid_request_error\"}") - got, e := apperror.GetStripeErrorMessage(es) - if e != nil { - t.Errorf("impossible to get the error message from Stripe built-in error: %v", e) - } - - if w := "Invalid API Key provided: sk_xxx"; got != w { - t.Errorf("Get the error message from Stripe built-in error is incorrect, got: %v want: %v", got, w) - } -} diff --git a/go.mod b/go.mod index 42e5171..022a048 100644 --- a/go.mod +++ b/go.mod @@ -1,14 +1,24 @@ module github.com/lelledaniele/upaygo -go 1.13 +go 1.21 require ( - github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 // indirect - github.com/go-chi/chi v4.0.2+incompatible // indirect - github.com/gorilla/mux v1.8.0 - github.com/stripe/stripe-go v62.10.0+incompatible - github.com/swaggo/http-swagger v0.0.0-20190614090009-c2865af9083e - github.com/swaggo/swag v1.6.7 // indirect - golang.org/x/text v0.3.4 // indirect - golang.org/x/tools v0.0.0-20190908135931-fef9eaa9e42b // indirect + github.com/gorilla/mux v1.8.1 + github.com/stripe/stripe-go/v76 v76.23.0 + github.com/swaggo/http-swagger/v2 v2.0.2 +) + +require ( + github.com/KyleBanks/depth v1.2.1 // indirect + github.com/go-openapi/jsonpointer v0.21.0 // indirect + github.com/go-openapi/jsonreference v0.21.0 // indirect + github.com/go-openapi/spec v0.21.0 // indirect + github.com/go-openapi/swag v0.23.0 // indirect + github.com/josharian/intern v1.0.0 // indirect + github.com/mailru/easyjson v0.7.7 // indirect + github.com/swaggo/files/v2 v2.0.0 // indirect + github.com/swaggo/swag v1.16.3 + golang.org/x/text v0.14.0 // indirect + golang.org/x/tools v0.19.0 // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index 603ce0e..f1cf3af 100644 --- a/go.sum +++ b/go.sum @@ -1,155 +1,59 @@ -github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/KyleBanks/depth v1.2.1 h1:5h8fQADFrWtarTdtDudMmGsC7GPbOAu6RVB3ffsVFHc= github.com/KyleBanks/depth v1.2.1/go.mod h1:jzSb9d0L43HxTQfT+oSA1EEp2q+ne2uh6XgeJcm8brE= -github.com/PuerkitoBio/purell v1.1.0 h1:rmGxhojJlM0tuKtfdvliR84CFHljx9ag64t2xmVkjK4= -github.com/PuerkitoBio/purell v1.1.0/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0= -github.com/PuerkitoBio/purell v1.1.1 h1:WEQqlqaGbrPkxLJWfBwQmfEAE1Z7ONdDLqrN38tNFfI= -github.com/PuerkitoBio/purell v1.1.1/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0= -github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 h1:d+Bc7a5rLufV/sSk/8dngufqelfh6jnri85riMAaF/M= -github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578/go.mod h1:uGdkoq3SwY9Y+13GIhn11/XLaGBb4BfwItxLd5jeuXE= -github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 h1:JYp7IbQjafoB+tBA3gMyHYHrpOtNuDiK/uB5uXxq5wM= -github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= -github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= -github.com/gin-contrib/gzip v0.0.1/go.mod h1:fGBJBCdt6qCZuCAOwWuFhBB4OOq9EFqlo5dEaFhhu5w= -github.com/gin-contrib/sse v0.0.0-20170109093832-22d885f9ecc7/go.mod h1:VJ0WA2NBN22VlZ2dKZQPAPnyWw5XTlK1KymzLKsr59s= -github.com/gin-contrib/sse v0.0.0-20190301062529-5545eab6dad3/go.mod h1:VJ0WA2NBN22VlZ2dKZQPAPnyWw5XTlK1KymzLKsr59s= -github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI= -github.com/gin-gonic/gin v1.3.0/go.mod h1:7cKuhb5qV2ggCFctp2fJQ+ErvciLZrIeoOSOm6mUr7Y= -github.com/gin-gonic/gin v1.4.0/go.mod h1:OW2EZn3DO8Ln9oIKOvM++LBO+5UPHJJDH72/q/3rZdM= -github.com/go-chi/chi v4.0.2+incompatible h1:maB6vn6FqCxrpz4FqWdh4+lwpyZIQS7YEAUcHlgXVRs= -github.com/go-chi/chi v4.0.2+incompatible/go.mod h1:eB3wogJHnLi3x/kFX2A+IbTBlXxmMeXJVKy9tTv1XzQ= -github.com/go-openapi/jsonpointer v0.17.0 h1:nH6xp8XdXHx8dqveo0ZuJBluCO2qGrPbDNZ0dwoRHP0= -github.com/go-openapi/jsonpointer v0.17.0/go.mod h1:cOnomiV+CVVwFLk0A/MExoFMjwdsUdVpsRhURCKh+3M= -github.com/go-openapi/jsonpointer v0.19.2/go.mod h1:3akKfEdA7DF1sugOqz1dVQHBcuDBPKZGEoHC/NkiQRg= -github.com/go-openapi/jsonpointer v0.19.3 h1:gihV7YNZK1iK6Tgwwsxo2rJbD1GTbdm72325Bq8FI3w= -github.com/go-openapi/jsonpointer v0.19.3/go.mod h1:Pl9vOtqEWErmShwVjC8pYs9cog34VGT37dQOVbmoatg= -github.com/go-openapi/jsonreference v0.17.0/go.mod h1:g4xxGn04lDIRh0GJb5QlpE3HfopLOL6uZrK/VgnsK9I= -github.com/go-openapi/jsonreference v0.19.0 h1:BqWKpV1dFd+AuiKlgtddwVIFQsuMpxfBDBHGfM2yNpk= -github.com/go-openapi/jsonreference v0.19.0/go.mod h1:g4xxGn04lDIRh0GJb5QlpE3HfopLOL6uZrK/VgnsK9I= -github.com/go-openapi/jsonreference v0.19.2/go.mod h1:jMjeRr2HHw6nAVajTXJ4eiUwohSTlpa0o73RUL1owJc= -github.com/go-openapi/jsonreference v0.19.3 h1:5cxNfTy0UVC3X8JL5ymxzyoUZmo8iZb+jeTWn7tUa8o= -github.com/go-openapi/jsonreference v0.19.3/go.mod h1:rjx6GuL8TTa9VaixXglHmQmIL98+wF9xc8zWvFonSJ8= -github.com/go-openapi/spec v0.19.0 h1:A4SZ6IWh3lnjH0rG0Z5lkxazMGBECtrZcbyYQi+64k4= -github.com/go-openapi/spec v0.19.0/go.mod h1:XkF/MOi14NmjsfZ8VtAKf8pIlbZzyoTvZsdfssdxcBI= -github.com/go-openapi/spec v0.19.3 h1:0XRyw8kguri6Yw4SxhsQA/atC88yqrk0+G4YhI2wabc= -github.com/go-openapi/spec v0.19.3/go.mod h1:FpwSN1ksY1eteniUU7X0N/BgJ7a4WvBFVA8Lj9mJglo= -github.com/go-openapi/spec v0.19.4 h1:ixzUSnHTd6hCemgtAJgluaTSGYpLNpJY4mA2DIkdOAo= -github.com/go-openapi/spec v0.19.4/go.mod h1:FpwSN1ksY1eteniUU7X0N/BgJ7a4WvBFVA8Lj9mJglo= -github.com/go-openapi/swag v0.17.0 h1:iqrgMg7Q7SvtbWLlltPrkMs0UBJI6oTSs79JFRUi880= -github.com/go-openapi/swag v0.17.0/go.mod h1:AByQ+nYG6gQg71GINrmuDXCPWdL640yX49/kXLo40Tg= -github.com/go-openapi/swag v0.19.2/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh66Z9tfKk= -github.com/go-openapi/swag v0.19.5 h1:lTz6Ys4CmqqCQmZPBlbQENR1/GucA2bzYTE12Pw4tFY= -github.com/go-openapi/swag v0.19.5/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh66Z9tfKk= -github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= -github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= -github.com/gorilla/mux v1.7.3 h1:gnP5JzjVOuiZD07fKKToCAOjS0yOpj/qPETTXCCS6hw= -github.com/gorilla/mux v1.7.3/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs= -github.com/gorilla/mux v1.7.4 h1:VuZ8uybHlWmqV03+zRzdwKL4tUnIp1MAQtp1mIFE1bc= -github.com/gorilla/mux v1.7.4/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So= -github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI= -github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So= -github.com/json-iterator/go v1.1.5/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= -github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= -github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= -github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= -github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= -github.com/kr/pty v1.1.5/go.mod h1:9r2w37qlBe7rQ6e1fg1S/9xpWHSnaqNdHD3WcMdbPDA= -github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= -github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= -github.com/mailru/easyjson v0.0.0-20180823135443-60711f1a8329 h1:2gxZ0XQIU/5z3Z3bUBu+FXuk2pFbkN6tcwi/pjyaDic= -github.com/mailru/easyjson v0.0.0-20180823135443-60711f1a8329/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= -github.com/mailru/easyjson v0.0.0-20190614124828-94de47d64c63/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= -github.com/mailru/easyjson v0.0.0-20190626092158-b2ccc519800e h1:hB2xlXdHp/pmPZq0y3QnmWAArdw9PqbmotexnWx/FU8= -github.com/mailru/easyjson v0.0.0-20190626092158-b2ccc519800e/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= -github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= -github.com/mattn/go-isatty v0.0.7/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= -github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= -github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= -github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= -github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I= -github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/go-openapi/jsonpointer v0.21.0 h1:YgdVicSA9vH5RiHs9TZW5oyafXZFc6+2Vc1rr/O9oNQ= +github.com/go-openapi/jsonpointer v0.21.0/go.mod h1:IUyH9l/+uyhIYQ/PXVA41Rexl+kOkAPDdXEYns6fzUY= +github.com/go-openapi/jsonreference v0.21.0 h1:Rs+Y7hSXT83Jacb7kFyjn4ijOuVGSvOdF2+tg1TRrwQ= +github.com/go-openapi/jsonreference v0.21.0/go.mod h1:LmZmgsrTkVg9LG4EaHeY8cBDslNPMo06cago5JNLkm4= +github.com/go-openapi/spec v0.21.0 h1:LTVzPc3p/RzRnkQqLRndbAzjY0d0BCL72A6j3CdL9ZY= +github.com/go-openapi/spec v0.21.0/go.mod h1:78u6VdPw81XU44qEWGhtr982gJ5BWg2c0I5XwVMotYk= +github.com/go-openapi/swag v0.23.0 h1:vsEVJDUo2hPJ2tu0/Xc+4noaxyEffXNIs3cOULZ+GrE= +github.com/go-openapi/swag v0.23.0/go.mod h1:esZ8ITTYEsH1V2trKHjAN8Ai7xHb8RV+YSZ577vPjgQ= +github.com/gorilla/mux v1.8.1 h1:TuBL49tXwgrFYWhqrNgrUNEY92u81SPhu7sTdzQEiWY= +github.com/gorilla/mux v1.8.1/go.mod h1:AKf9I4AEqPTmMytcMc0KkNouC66V3BtZ4qD5fmWSiMQ= +github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY= +github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y= +github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= +github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= +github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= +github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= +github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0= +github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= -github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0= -github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= +github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M= +github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE= -github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= -github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q= -github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= -github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk= -github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= -github.com/stripe/stripe-go v61.27.0+incompatible h1:p0HgsaOYus3VbiUS26GgnZ/wa3ipIFa+NKoX74mVsHA= -github.com/stripe/stripe-go v61.27.0+incompatible/go.mod h1:A1dQZmO/QypXmsL0T8axYZkSN/uA/T/A64pfKdBAMiY= -github.com/stripe/stripe-go v62.9.0+incompatible h1:O9SBIruVc8uMdyxSVMSXiKZRujnn45bpn8eAyn8BfcQ= -github.com/stripe/stripe-go v62.9.0+incompatible/go.mod h1:A1dQZmO/QypXmsL0T8axYZkSN/uA/T/A64pfKdBAMiY= -github.com/stripe/stripe-go v62.10.0+incompatible h1:NA0ZdyXlogeRY1YRmx3xL3/4r3vQjAU3Y175+IwFoYo= -github.com/stripe/stripe-go v62.10.0+incompatible/go.mod h1:A1dQZmO/QypXmsL0T8axYZkSN/uA/T/A64pfKdBAMiY= -github.com/swaggo/files v0.0.0-20190704085106-630677cd5c14 h1:PyYN9JH5jY9j6av01SpfRMb+1DWg/i3MbGOKPxJ2wjM= -github.com/swaggo/files v0.0.0-20190704085106-630677cd5c14/go.mod h1:gxQT6pBGRuIGunNf/+tSOB5OHvguWi8Tbt82WOkf35E= -github.com/swaggo/gin-swagger v1.2.0/go.mod h1:qlH2+W7zXGZkczuL+r2nEBR2JTT+/lX05Nn6vPhc7OI= -github.com/swaggo/http-swagger v0.0.0-20190614090009-c2865af9083e h1:m5sYJ43teIUlESuKRFQRRm7kqi6ExiYwVKfoXNuRgHU= -github.com/swaggo/http-swagger v0.0.0-20190614090009-c2865af9083e/go.mod h1:eycbshptIv+tqTMlLEaGC2noPNcetbrcYEelLafrIDI= -github.com/swaggo/swag v1.5.1/go.mod h1:1Bl9F/ZBpVWh22nY0zmYyASPO1lI/zIwRDrpZU+tv8Y= -github.com/swaggo/swag v1.6.2 h1:WQMAtT/FmMBb7g0rAuHDhG3vvdtHKJ3WZ+Ssb0p4Y6E= -github.com/swaggo/swag v1.6.2/go.mod h1:YyZstMc22WYm6GEDx/CYWxq+faBbjQ5EqwQcrjREDBo= -github.com/swaggo/swag v1.6.7 h1:e8GC2xDllJZr3omJkm9YfmK0Y56+rMO3cg0JBKNz09s= -github.com/swaggo/swag v1.6.7/go.mod h1:xDhTyuFIujYiN3DKWC/H/83xcfHp+UE/IzWWampG7Zc= -github.com/ugorji/go v1.1.4/go.mod h1:uQMGLiO92mf5W77hV/PUCpI3pbzQx3CRekS0kk+RGrc= -github.com/ugorji/go v1.1.5-pre/go.mod h1:FwP/aQVg39TXzItUBMwnWp9T9gPQnXw4Poh4/oBQZ/0= -github.com/ugorji/go/codec v0.0.0-20181022190402-e5e69e061d4f/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0= -github.com/ugorji/go/codec v1.1.5-pre/go.mod h1:tULtS6Gy1AE1yCENaw4Vb//HLH5njI2tfCQDUqRd8fI= -github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA= -github.com/urfave/cli/v2 v2.1.1/go.mod h1:SE9GqnLQmjVa0iPEY0f1w3ygNIYcIJ0OKPMoW2caLfQ= -golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/crypto v0.0.0-20190611184440-5c40567a22f8/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= -golang.org/x/net v0.0.0-20181005035420-146acd28ed58/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20181220203305-927f97764cc3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20190311183353-d8887717615a h1:oWX7TPOiFAMXLq8o0ikBYfCJVlRHBcsciT5bXOrH628= -golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/net v0.0.0-20190503192946-f4e77d36d62c/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/net v0.0.0-20190611141213-3f473d35a33a/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20190613194153-d28f0bde5980/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20190827160401-ba9fcec4b297 h1:k7pJ2yAPLPgbskkFdhRCsA77k2fySZ1zf2zCjvQCiIM= -golang.org/x/net v0.0.0-20190827160401-ba9fcec4b297/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sys v0.0.0-20181228144115-9a3f9b0469bb/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190610200419-93c9922d18ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190616124812-15dcb6c0061f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg= -golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs= -golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= -golang.org/x/text v0.3.3 h1:cokOdA+Jmi5PJGXLlLllQSgYigAEfHXJAERHVMaCc2k= -golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.3.4 h1:0YWbFKbhXG/wIiuHDSKpS0Iy7FSA+u45VtBMfQcFTTc= -golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= +github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/stripe/stripe-go/v76 v76.23.0 h1:LCnTghh1x9d7r9rPbr2BcrQZ6oLpNSkT/rIWGkuMBHc= +github.com/stripe/stripe-go/v76 v76.23.0/go.mod h1:rw1MxjlAKKcZ+3FOXgTHgwiOa2ya6CPq6ykpJ0Q6Po4= +github.com/swaggo/files/v2 v2.0.0 h1:hmAt8Dkynw7Ssz46F6pn8ok6YmGZqHSVLZ+HQM7i0kw= +github.com/swaggo/files/v2 v2.0.0/go.mod h1:24kk2Y9NYEJ5lHuCra6iVwkMjIekMCaFq/0JQj66kyM= +github.com/swaggo/http-swagger/v2 v2.0.2 h1:FKCdLsl+sFCx60KFsyM0rDarwiUSZ8DqbfSyIKC9OBg= +github.com/swaggo/http-swagger/v2 v2.0.2/go.mod h1:r7/GBkAWIfK6E/OLnE8fXnviHiDeAHmgIyooa4xm3AQ= +github.com/swaggo/swag v1.16.3 h1:PnCYjPCah8FK4I26l2F/KQ4yz3sILcVUN3cTlBFA9Pg= +github.com/swaggo/swag v1.16.3/go.mod h1:DImHIuOFXKpMFAQjcC7FG4m3Dg4+QuUgUzJmKjI/gRk= +golang.org/x/mod v0.16.0 h1:QX4fJ0Rr5cPQCF7O9lh9Se4pmwfwskqZfq5moyldzic= +golang.org/x/mod v0.16.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= +golang.org/x/net v0.0.0-20210520170846-37e1c6afe023/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= +golang.org/x/net v0.22.0 h1:9sGLhx7iRIHEiX0oAJ3MRZMUCElJgy7Br1nO+AMN3Tc= +golang.org/x/net v0.22.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg= +golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= +golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= +golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/tools v0.0.0-20190606050223-4d9ae51c2468 h1:fTfk6GjmihJbK0mSUFgPPgYpsdmApQ86Mcd4GuKax9U= -golang.org/x/tools v0.0.0-20190606050223-4d9ae51c2468/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= -golang.org/x/tools v0.0.0-20190611222205-d73e1c7e250b/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= -golang.org/x/tools v0.0.0-20190614205625-5aca471b1d59/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= -golang.org/x/tools v0.0.0-20190908135931-fef9eaa9e42b h1:s3JPx1wx+Kydg1rKI8uzmNMeYA+rr9m5kiLGVqEBufM= -golang.org/x/tools v0.0.0-20190908135931-fef9eaa9e42b/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= +golang.org/x/tools v0.19.0 h1:tfGCXNR1OsFG+sVdLAitlpjAvD/I6dHDKnYrpEZUHkw= +golang.org/x/tools v0.19.0/go.mod h1:qoJWxmGSIBmAeriMx19ogtrEPrGtDbPK634QFIcLAhc= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= -gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/go-playground/assert.v1 v1.2.1/go.mod h1:9RXL0bg/zibRAgZUYszZSwO/z8Y/a8bDuhia5mkpMnE= -gopkg.in/go-playground/validator.v8 v8.18.2/go.mod h1:RX2a/7Ha8BgOhfk7j780h4/u/RRjR0eouCJSH80/M2Y= -gopkg.in/yaml.v2 v2.2.1 h1:mUhvW9EsL+naU5Q3cakzfE91YhliOondGd6ZrsDBHQE= -gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw= -gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/main.go b/main.go index 4446d04..f85e980 100644 --- a/main.go +++ b/main.go @@ -14,10 +14,11 @@ import ( apprestintentcreate "github.com/lelledaniele/upaygo/controller/rest/intent/create" apprestintentget "github.com/lelledaniele/upaygo/controller/rest/intent/get" - httpSwagger "github.com/swaggo/http-swagger" + httpSwagger "github.com/swaggo/http-swagger/v2" "github.com/gorilla/mux" - _ "github.com/lelledaniele/upaygo/docs" + + _ "github.com/lelledaniele/upaygo/docs" // for swagger documentation generation ) var configFile string diff --git a/payment/intent/cancel/intentcancel.go b/payment/intent/cancel/intentcancel.go index ab3146b..f2ef842 100644 --- a/payment/intent/cancel/intentcancel.go +++ b/payment/intent/cancel/intentcancel.go @@ -8,8 +8,8 @@ import ( apperror "github.com/lelledaniele/upaygo/error" apppaymentintent "github.com/lelledaniele/upaygo/payment/intent" - "github.com/stripe/stripe-go" - "github.com/stripe/stripe-go/paymentintent" + "github.com/stripe/stripe-go/v76" + "github.com/stripe/stripe-go/v76/paymentintent" ) // Cancel gets the intent id from c Stripe account and cancel it diff --git a/payment/intent/cancel/intentcancel_integration_test.go b/payment/intent/cancel/intentcancel_integration_test.go deleted file mode 100644 index 0080654..0000000 --- a/payment/intent/cancel/intentcancel_integration_test.go +++ /dev/null @@ -1,149 +0,0 @@ -// +build stripe - -package apppaymentintentcancel_test - -import ( - "flag" - "fmt" - "os" - "testing" - - appconfig "github.com/lelledaniele/upaygo/config" - appcurrency "github.com/lelledaniele/upaygo/currency" - apppaymentintentcancel "github.com/lelledaniele/upaygo/payment/intent/cancel" - - "github.com/stripe/stripe-go" - "github.com/stripe/stripe-go/paymentintent" -) - -func TestMain(m *testing.M) { - var fcp string - - flag.StringVar(&fcp, "config", "", "Provide config file as an absolute path") - flag.Parse() - - if fcp == "" { - fmt.Print("Integration Stripe test needs the config file absolute path as flag -config") - os.Exit(1) - } - - fc, e := os.Open(fcp) - if e != nil { - fmt.Printf("Impossible to get configuration file: %v\n", e) - os.Exit(1) - } - defer fc.Close() - - e = appconfig.ImportConfig(fc) - if e != nil { - fmt.Printf("Error durring file config import: %v", e) - os.Exit(1) - } - - os.Exit(m.Run()) -} - -func TestCancel(t *testing.T) { - cur, _ := appcurrency.New("EUR") - am := int64(2088) - pip := &stripe.PaymentIntentParams{ - Amount: stripe.Int64(am), - Currency: stripe.String(cur.GetISO4217()), - ConfirmationMethod: stripe.String("automatic"), - Confirm: stripe.Bool(true), - CaptureMethod: stripe.String("manual"), - PaymentMethod: stripe.String("pm_card_visa"), - } - - sck, _ := appconfig.GetStripeAPIConfigByCurrency(cur.GetISO4217()) - stripe.Key = sck.GetSK() - - intent, e := paymentintent.New(pip) - if e != nil { - t.Errorf("impossible to create a new payment intent for testing: %v", e) - } - - appintent, e := apppaymentintentcancel.Cancel(intent.ID, cur) - if e != nil { - t.Errorf("impossible to cancel %v payment intent: %v", intent.ID, e) - } - - if !appintent.IsCanceled() { - t.Error("intent cancel is incorrect, got an intent that is not canceled") - } -} - -func TestCancelWithSCACard(t *testing.T) { - cur, _ := appcurrency.New("EUR") - am := int64(2088) - pip := &stripe.PaymentIntentParams{ - Amount: stripe.Int64(am), - Currency: stripe.String(cur.GetISO4217()), - ConfirmationMethod: stripe.String("automatic"), - Confirm: stripe.Bool(true), - CaptureMethod: stripe.String("manual"), - PaymentMethod: stripe.String("pm_card_authenticationRequiredOnSetup"), - } - - sck, _ := appconfig.GetStripeAPIConfigByCurrency(cur.GetISO4217()) - stripe.Key = sck.GetSK() - - intent, e := paymentintent.New(pip) - if e != nil { - t.Errorf("impossible to create a new payment intent for testing: %v", e) - } - - appintent, e := apppaymentintentcancel.Cancel(intent.ID, cur) - if e != nil { - t.Errorf("impossible to cancel %v payment intent: %v", intent.ID, e) - } - - if !appintent.IsCanceled() { - t.Error("intent cancel is incorrect, got an intent that is not canceled") - } -} - -func TestCancelNonConfirmedIntent(t *testing.T) { - cur, _ := appcurrency.New("EUR") - am := int64(2088) - pip := &stripe.PaymentIntentParams{ - Amount: stripe.Int64(am), - Currency: stripe.String(cur.GetISO4217()), - ConfirmationMethod: stripe.String("manual"), - Confirm: stripe.Bool(false), - CaptureMethod: stripe.String("manual"), - PaymentMethod: stripe.String("pm_card_authenticationRequiredOnSetup"), - } - - sck, _ := appconfig.GetStripeAPIConfigByCurrency(cur.GetISO4217()) - stripe.Key = sck.GetSK() - - intent, e := paymentintent.New(pip) - if e != nil { - t.Errorf("impossible to create a new payment intent for testing: %v", e) - } - - appintent, e := apppaymentintentcancel.Cancel(intent.ID, cur) - if e != nil { - t.Errorf("impossible to cancel %v payment intent: %v", intent.ID, e) - } - - if !appintent.IsCanceled() { - t.Error("intent cancel is incorrect, got an intent that is not canceled") - } -} - -func TestCancelWithoutID(t *testing.T) { - cur, _ := appcurrency.New("EUR") - _, e := apppaymentintentcancel.Cancel("", cur) - if e == nil { - t.Error("expecting an error if cancel an intent without ID") - } -} - -func TestCancelWithoutCurrency(t *testing.T) { - _, e := apppaymentintentcancel.Cancel("in_xxx", nil) - if e == nil { - t.Error("expecting an error if cancel an intent without currency") - } -} diff --git a/payment/intent/capture/intentcapture.go b/payment/intent/capture/intentcapture.go index 37288dc..cd7e356 100644 --- a/payment/intent/capture/intentcapture.go +++ b/payment/intent/capture/intentcapture.go @@ -8,8 +8,8 @@ import ( apperror "github.com/lelledaniele/upaygo/error" apppaymentintent "github.com/lelledaniele/upaygo/payment/intent" - "github.com/stripe/stripe-go" - "github.com/stripe/stripe-go/paymentintent" + "github.com/stripe/stripe-go/v76" + "github.com/stripe/stripe-go/v76/paymentintent" ) // Capture gets the intent id from c Stripe account and capture it diff --git a/payment/intent/capture/intentcapture_integration_test.go b/payment/intent/capture/intentcapture_integration_test.go deleted file mode 100644 index b01b9d9..0000000 --- a/payment/intent/capture/intentcapture_integration_test.go +++ /dev/null @@ -1,119 +0,0 @@ -// +build stripe - -package apppaymentintentcapture_test - -import ( - "flag" - "fmt" - "os" - "testing" - - appconfig "github.com/lelledaniele/upaygo/config" - appcurrency "github.com/lelledaniele/upaygo/currency" - apppaymentintentcapture "github.com/lelledaniele/upaygo/payment/intent/capture" - - "github.com/stripe/stripe-go" - "github.com/stripe/stripe-go/paymentintent" -) - -func TestMain(m *testing.M) { - var fcp string - - flag.StringVar(&fcp, "config", "", "Provide config file as an absolute path") - flag.Parse() - - if fcp == "" { - fmt.Print("Integration Stripe test needs the config file absolute path as flag -config") - os.Exit(1) - } - - fc, e := os.Open(fcp) - if e != nil { - fmt.Printf("Impossible to get configuration file: %v\n", e) - os.Exit(1) - } - defer fc.Close() - - e = appconfig.ImportConfig(fc) - if e != nil { - fmt.Printf("Error durring file config import: %v", e) - os.Exit(1) - } - - os.Exit(m.Run()) -} - -func TestCapture(t *testing.T) { - cur, _ := appcurrency.New("EUR") - am := int64(2088) - pip := &stripe.PaymentIntentParams{ - Amount: stripe.Int64(am), - Currency: stripe.String(cur.GetISO4217()), - ConfirmationMethod: stripe.String("automatic"), - Confirm: stripe.Bool(true), - CaptureMethod: stripe.String("manual"), - PaymentMethod: stripe.String("pm_card_visa"), - } - - sck, _ := appconfig.GetStripeAPIConfigByCurrency(cur.GetISO4217()) - stripe.Key = sck.GetSK() - - intent, e := paymentintent.New(pip) - if e != nil { - t.Errorf("impossible to create a new payment intent for testing: %v", e) - } - - appintent, e := apppaymentintentcapture.Capture(intent.ID, cur) - if e != nil { - t.Errorf("impossible to capture %v payment intent: %v", intent.ID, e) - } - - if !appintent.IsSucceeded() { - t.Error("intent capture is incorrect, got an intent that is not succeeded") - } - - _, _ = paymentintent.Cancel(appintent.GetGatewayReference(), nil) -} - -func TestCaptureWithSCACard(t *testing.T) { - cur, _ := appcurrency.New("EUR") - am := int64(2088) - pip := &stripe.PaymentIntentParams{ - Amount: stripe.Int64(am), - Currency: stripe.String(cur.GetISO4217()), - ConfirmationMethod: stripe.String("automatic"), - Confirm: stripe.Bool(true), - CaptureMethod: stripe.String("manual"), - PaymentMethod: stripe.String("pm_card_authenticationRequiredOnSetup"), - } - - sck, _ := appconfig.GetStripeAPIConfigByCurrency(cur.GetISO4217()) - stripe.Key = sck.GetSK() - - intent, e := paymentintent.New(pip) - if e != nil { - t.Errorf("impossible to create a new payment intent for testing: %v", e) - } - - _, e = apppaymentintentcapture.Capture(intent.ID, cur) - if e == nil { - t.Errorf("intent %v should not be captured as it should have status requires_action", intent.ID) - } - - _, _ = paymentintent.Cancel(intent.ID, nil) -} - -func TestCaptureWithoutID(t *testing.T) { - cur, _ := appcurrency.New("EUR") - _, e := apppaymentintentcapture.Capture("", cur) - if e == nil { - t.Error("expecting an error if capture an intent without ID") - } -} - -func TestCaptureWithoutCurrency(t *testing.T) { - _, e := apppaymentintentcapture.Capture("in_xxx", nil) - if e == nil { - t.Error("expecting an error if capture an intent without currency") - } -} diff --git a/payment/intent/confirm/intentconfirm.go b/payment/intent/confirm/intentconfirm.go index d20d9f4..be26780 100644 --- a/payment/intent/confirm/intentconfirm.go +++ b/payment/intent/confirm/intentconfirm.go @@ -8,8 +8,8 @@ import ( apperror "github.com/lelledaniele/upaygo/error" apppaymentintent "github.com/lelledaniele/upaygo/payment/intent" - "github.com/stripe/stripe-go" - "github.com/stripe/stripe-go/paymentintent" + "github.com/stripe/stripe-go/v76" + "github.com/stripe/stripe-go/v76/paymentintent" ) // Confirm gets the intent id from c Stripe account and confirm it diff --git a/payment/intent/confirm/intentconfirm_integration_test.go b/payment/intent/confirm/intentconfirm_integration_test.go deleted file mode 100644 index 4832862..0000000 --- a/payment/intent/confirm/intentconfirm_integration_test.go +++ /dev/null @@ -1,89 +0,0 @@ -// +build stripe - -package apppaymentintentconfirm_test - -import ( - "flag" - "fmt" - "os" - "testing" - - appconfig "github.com/lelledaniele/upaygo/config" - appcurrency "github.com/lelledaniele/upaygo/currency" - apppaymentintentconfirm "github.com/lelledaniele/upaygo/payment/intent/confirm" - - "github.com/stripe/stripe-go" - "github.com/stripe/stripe-go/paymentintent" -) - -func TestMain(m *testing.M) { - var fcp string - - flag.StringVar(&fcp, "config", "", "Provide config file as an absolute path") - flag.Parse() - - if fcp == "" { - fmt.Print("Integration Stripe test needs the config file absolute path as flag -config") - os.Exit(1) - } - - fc, e := os.Open(fcp) - if e != nil { - fmt.Printf("Impossible to get configuration file: %v\n", e) - os.Exit(1) - } - defer fc.Close() - - e = appconfig.ImportConfig(fc) - if e != nil { - fmt.Printf("Error durring file config import: %v", e) - os.Exit(1) - } - - os.Exit(m.Run()) -} - -func TestConfirm(t *testing.T) { - cur, _ := appcurrency.New("EUR") - am := int64(2088) - pip := &stripe.PaymentIntentParams{ - Amount: stripe.Int64(am), - Currency: stripe.String(cur.GetISO4217()), - ConfirmationMethod: stripe.String("manual"), - PaymentMethod: stripe.String("pm_card_visa"), - } - - sck, _ := appconfig.GetStripeAPIConfigByCurrency(cur.GetISO4217()) - stripe.Key = sck.GetSK() - - intent, e := paymentintent.New(pip) - if e != nil { - t.Errorf("impossible to create a new payment intent for testing: %v", e) - } - - appintent, e := apppaymentintentconfirm.Confirm(intent.ID, cur) - if e != nil { - t.Errorf("impossible to confirm %v payment intent: %v", intent.ID, e) - } - - if appintent.RequiresConfirmation() { - t.Error("intent confirmation is incorrect, got an intent that requires confirmation") - } - - _, _ = paymentintent.Cancel(appintent.GetGatewayReference(), nil) -} - -func TestConfirmWithoutID(t *testing.T) { - cur, _ := appcurrency.New("EUR") - _, e := apppaymentintentconfirm.Confirm("", cur) - if e == nil { - t.Error("expecting an error if confirm an intent without ID") - } -} - -func TestConfirmWithoutCurrency(t *testing.T) { - _, e := apppaymentintentconfirm.Confirm("in_xxx", nil) - if e == nil { - t.Error("expecting an error if confirm an intent without currency") - } -} diff --git a/payment/intent/create/intentcreate.go b/payment/intent/create/intentcreate.go index 3bbd004..59066a1 100644 --- a/payment/intent/create/intentcreate.go +++ b/payment/intent/create/intentcreate.go @@ -10,8 +10,8 @@ import ( apppaymentintent "github.com/lelledaniele/upaygo/payment/intent" apppaymentsource "github.com/lelledaniele/upaygo/payment/source" - "github.com/stripe/stripe-go" - "github.com/stripe/stripe-go/paymentintent" + "github.com/stripe/stripe-go/v76" + "github.com/stripe/stripe-go/v76/paymentintent" ) // Create creates an intent in Stripe and returns it as an instance of Intent @@ -31,14 +31,14 @@ func Create(a appamount.Amount, p apppaymentsource.Source, c appcustomer.Custome Amount: stripe.Int64(int64(a.GetAmount())), Currency: stripe.String(a.GetCurrency().GetISO4217()), PaymentMethod: stripe.String(p.GetGatewayReference()), - SetupFutureUsage: stripe.String("off_session"), ConfirmationMethod: stripe.String("manual"), CaptureMethod: stripe.String("manual"), + OffSession: stripe.Bool(true), + Confirm: stripe.Bool(true), } if c != nil { ic.Customer = stripe.String(c.GetGatewayReference()) - ic.SavePaymentMethod = stripe.Bool(true) } intent, e := paymentintent.New(ic) diff --git a/payment/intent/create/intentcreate_integration_test.go b/payment/intent/create/intentcreate_integration_test.go deleted file mode 100644 index 876d6c7..0000000 --- a/payment/intent/create/intentcreate_integration_test.go +++ /dev/null @@ -1,148 +0,0 @@ -// +build stripe - -package apppaymentintentcreate_test - -import ( - "flag" - "fmt" - "os" - "testing" - - appamount "github.com/lelledaniele/upaygo/amount" - appconfig "github.com/lelledaniele/upaygo/config" - appcurrency "github.com/lelledaniele/upaygo/currency" - appcustomer "github.com/lelledaniele/upaygo/customer" - apppaymentintentcreate "github.com/lelledaniele/upaygo/payment/intent/create" - apppaymentsource "github.com/lelledaniele/upaygo/payment/source" - - "github.com/stripe/stripe-go/customer" - "github.com/stripe/stripe-go/paymentintent" -) - -func TestMain(m *testing.M) { - var fcp string - - flag.StringVar(&fcp, "config", "", "Provide config file as an absolute path") - flag.Parse() - - if fcp == "" { - fmt.Print("Integration Stripe test needs the config file absolute path as flag -config") - os.Exit(1) - } - - fc, e := os.Open(fcp) - if e != nil { - fmt.Printf("Impossible to get configuration file: %v\n", e) - os.Exit(1) - } - defer fc.Close() - - e = appconfig.ImportConfig(fc) - if e != nil { - fmt.Printf("Error durring file config import: %v", e) - os.Exit(1) - } - - os.Exit(m.Run()) -} - -func TestCreate(t *testing.T) { - cur, _ := appcurrency.New("EUR") - am := 2045 - cus, _ := appcustomer.NewStripe("email@email.com", cur) - a, _ := appamount.New(am, cur.GetISO4217()) - ps := apppaymentsource.New("pm_card_visa") - - pi, e := apppaymentintentcreate.Create(a, ps, cus) - if e != nil { - t.Errorf("impossible to create a new payment intent: %v", e) - } - - if pi.GetGatewayReference() == "" { - t.Error("intent new is incorrect, created an intent without gateway reference") - } - - if pi.GetConfirmationMethod() != "manual" { - t.Errorf("intent should have confirmation method set to manual, got %v", pi.GetConfirmationMethod()) - } - - if pi.GetNextAction() != "" { - t.Errorf("intent should not have next action as it is not confirmed, got %v", pi.GetNextAction()) - } - - if !pi.IsOffSession() { - t.Error("intent should be enable for off session payment") - } - - if pi.GetCreatedAt().Unix() == 0 { - t.Error("intent should have a create timestamp") - } - - if pi.GetCustomer().GetGatewayReference() != cus.GetGatewayReference() { - t.Errorf("intent customer is incorrect, got: %v want %v", pi.GetCustomer(), cus) - } - - if pi.GetSource().GetGatewayReference() == "" { - t.Error("intent source is empty") - } - - if !pi.GetAmount().Equal(a) { - t.Errorf("intent amount is incorrect, got: %v want %v", pi.GetAmount(), a) - } - - if pi.IsCanceled() { - t.Error("a new intent should not be cancelled") - } - - if pi.IsSucceeded() { - t.Error("a new intent should not be succeeded") - } - - if pi.RequiresCapture() { - t.Error("a new intent should not require capture") - } - - if !pi.RequiresConfirmation() { - t.Error("a new intent should require confirmation") - } - - _, _ = paymentintent.Cancel(pi.GetGatewayReference(), nil) - _, _ = customer.Del(cus.GetGatewayReference(), nil) -} - -func TestCreateWithoutCustomer(t *testing.T) { - cur, _ := appcurrency.New("EUR") - am := 2045 - a, _ := appamount.New(am, cur.GetISO4217()) - ps := apppaymentsource.New("pm_card_visa") - - pi, e := apppaymentintentcreate.Create(a, ps, nil) - if e != nil { - t.Errorf("impossible to create a new payment intent: %v", e) - } - - if pi.GetCustomer() != nil { - t.Errorf("intent customer should be blank, got: %v", pi.GetCustomer()) - } - - _, _ = paymentintent.Cancel(pi.GetGatewayReference(), nil) -} - -func TestCreateWithoutAmount(t *testing.T) { - ps := apppaymentsource.New("pm_card_visa") - - _, e := apppaymentintentcreate.Create(nil, ps, nil) - if e == nil { - t.Error("intent without amount created") - } -} - -func TestCreateWithoutPaymentSource(t *testing.T) { - am := 2045 - a, _ := appamount.New(am, "EUR") - - _, e := apppaymentintentcreate.Create(a, nil, nil) - if e == nil { - t.Error("intent without amount created") - } -} diff --git a/payment/intent/get/intentget.go b/payment/intent/get/intentget.go index 5e6ea60..0d60be3 100644 --- a/payment/intent/get/intentget.go +++ b/payment/intent/get/intentget.go @@ -8,8 +8,8 @@ import ( apperror "github.com/lelledaniele/upaygo/error" apppaymentintent "github.com/lelledaniele/upaygo/payment/intent" - "github.com/stripe/stripe-go" - "github.com/stripe/stripe-go/paymentintent" + "github.com/stripe/stripe-go/v76" + "github.com/stripe/stripe-go/v76/paymentintent" ) // Get gets the gf intent from c Stripe account and returns it as an instance of i diff --git a/payment/intent/get/intentget_integration_test.go b/payment/intent/get/intentget_integration_test.go deleted file mode 100644 index 53ad2f2..0000000 --- a/payment/intent/get/intentget_integration_test.go +++ /dev/null @@ -1,87 +0,0 @@ -// +build stripe - -package apppaymentintentget_test - -import ( - "flag" - "fmt" - "os" - "testing" - - appconfig "github.com/lelledaniele/upaygo/config" - appcurrency "github.com/lelledaniele/upaygo/currency" - apppaymentintentget "github.com/lelledaniele/upaygo/payment/intent/get" - - "github.com/stripe/stripe-go" - "github.com/stripe/stripe-go/paymentintent" -) - -func TestMain(m *testing.M) { - var fcp string - - flag.StringVar(&fcp, "config", "", "Provide config file as an absolute path") - flag.Parse() - - if fcp == "" { - fmt.Print("Integration Stripe test needs the config file absolute path as flag -config") - os.Exit(1) - } - - fc, e := os.Open(fcp) - if e != nil { - fmt.Printf("Impossible to get configuration file: %v\n", e) - os.Exit(1) - } - defer fc.Close() - - e = appconfig.ImportConfig(fc) - if e != nil { - fmt.Printf("Error durring file config import: %v", e) - os.Exit(1) - } - - os.Exit(m.Run()) -} - -func TestGet(t *testing.T) { - cur, _ := appcurrency.New("EUR") - am := int64(2088) - pip := &stripe.PaymentIntentParams{ - Amount: stripe.Int64(am), - Currency: stripe.String(cur.GetISO4217()), - } - - sck, _ := appconfig.GetStripeAPIConfigByCurrency(cur.GetISO4217()) - stripe.Key = sck.GetSK() - - intent, e := paymentintent.New(pip) - if e != nil { - t.Errorf("impossible to create a new payment intent for testing: %v", e) - } - - appintent, e := apppaymentintentget.Get(intent.ID, cur) - if e != nil { - t.Errorf("impossible to get %v payment intent: %v", intent.ID, e) - } - - if appintent.GetGatewayReference() != intent.ID { - t.Errorf("intent get is incorrect, got an intent with different ID. Got: %v want: %v", appintent.GetGatewayReference(), intent.ID) - } - - _, _ = paymentintent.Cancel(appintent.GetGatewayReference(), nil) -} - -func TestGetWithoutID(t *testing.T) { - cur, _ := appcurrency.New("EUR") - _, e := apppaymentintentget.Get("", cur) - if e == nil { - t.Error("expecting an error if get an intent without ID") - } -} - -func TestGetWithoutCurrency(t *testing.T) { - _, e := apppaymentintentget.Get("in_xxx", nil) - if e == nil { - t.Error("expecting an error if get an intent without currency") - } -} diff --git a/payment/intent/stripeconv.go b/payment/intent/stripeconv.go index 9309001..074c013 100644 --- a/payment/intent/stripeconv.go +++ b/payment/intent/stripeconv.go @@ -7,7 +7,7 @@ import ( appcustomer "github.com/lelledaniele/upaygo/customer" apppaymentsource "github.com/lelledaniele/upaygo/payment/source" - "github.com/stripe/stripe-go" + "github.com/stripe/stripe-go/v76" ) func FromStripeToAppIntent(intent stripe.PaymentIntent) Intent { @@ -22,7 +22,7 @@ func FromStripeToAppIntent(intent stripe.PaymentIntent) Intent { ps = apppaymentsource.New(intent.PaymentMethod.ID) } - a, _ := appamount.New(int(intent.Amount), intent.Currency) + a, _ := appamount.New(int(intent.Amount), string(intent.Currency)) var cus appcustomer.Customer if intent.Customer != nil { diff --git a/payment/intent/stripeconv_test.go b/payment/intent/stripeconv_test.go deleted file mode 100644 index 301f4b1..0000000 --- a/payment/intent/stripeconv_test.go +++ /dev/null @@ -1,121 +0,0 @@ -// +build unit - -package apppaymentintent_test - -import ( - "testing" - - apppaymentintent "github.com/lelledaniele/upaygo/payment/intent" - - "github.com/stripe/stripe-go" -) - -func TestFromStripeToAppIntent(t *testing.T) { - pmID := "card_xxx" - pm := stripe.PaymentMethod{ - ID: pmID, - } - - nat := "stripe_sdk" - na := stripe.PaymentIntentNextAction{ - Type: stripe.PaymentIntentNextActionType(nat), - } - - cusID := "cus_xxx" - cus := stripe.Customer{ - ID: cusID, - } - - intent := stripe.PaymentIntent{ - ID: "intent_xxx", - NextAction: &na, - PaymentMethod: &pm, - Customer: &cus, - } - - appintent := apppaymentintent.FromStripeToAppIntent(intent) - - if appintent.GetNextAction() != nat { - t.Errorf("incorrect next_action intent domain conversion, got: %v want: %v", appintent.GetNextAction(), nat) - } - - if appintent.GetSource().GetGatewayReference() != pmID { - t.Errorf("incorrect payment_method intent domain conversion, got: %v want: %v", appintent.GetSource().GetGatewayReference(), pmID) - } - - if appintent.GetCustomer().GetGatewayReference() != cusID { - t.Errorf("incorrect customer intent domain conversion, got: %v want: %v", appintent.GetCustomer().GetGatewayReference(), cusID) - } -} - -func TestFromStripeToAppIntentWithoutNextAction(t *testing.T) { - pmID := "card_xxx" - pm := stripe.PaymentMethod{ - ID: pmID, - } - - cusID := "cus_xxx" - cus := stripe.Customer{ - ID: cusID, - } - - intent := stripe.PaymentIntent{ - ID: "intent_xxx", - PaymentMethod: &pm, - Customer: &cus, - } - - appintent := apppaymentintent.FromStripeToAppIntent(intent) - - if appintent.GetNextAction() != "" { - t.Errorf("incorrect next_action intent domain conversion, got: %v want: ''", appintent.GetNextAction()) - } -} - -func TestFromStripeToAppIntentWithoutPaymentMethod(t *testing.T) { - nat := "stripe_sdk" - na := stripe.PaymentIntentNextAction{ - Type: stripe.PaymentIntentNextActionType(nat), - } - - cusID := "cus_xxx" - cus := stripe.Customer{ - ID: cusID, - } - - intent := stripe.PaymentIntent{ - ID: "intent_xxx", - NextAction: &na, - Customer: &cus, - } - - appintent := apppaymentintent.FromStripeToAppIntent(intent) - - if appintent.GetSource() != nil { - t.Errorf("incorrect payment_method intent domain conversion, got: %v want: nil", appintent.GetSource().GetGatewayReference()) - } -} - -func TestFromStripeToAppIntentWithoutCustomer(t *testing.T) { - pmID := "card_xxx" - pm := stripe.PaymentMethod{ - ID: pmID, - } - - nat := "stripe_sdk" - na := stripe.PaymentIntentNextAction{ - Type: stripe.PaymentIntentNextActionType(nat), - } - - intent := stripe.PaymentIntent{ - ID: "intent_xxx", - NextAction: &na, - PaymentMethod: &pm, - } - - appintent := apppaymentintent.FromStripeToAppIntent(intent) - - if appintent.GetCustomer() != nil { - t.Errorf("incorrect customer intent domain conversion, got: %v want: nil", appintent.GetCustomer().GetGatewayReference()) - } -} diff --git a/payment/source/paymentsource_test.go b/payment/source/paymentsource_test.go deleted file mode 100644 index 004668c..0000000 --- a/payment/source/paymentsource_test.go +++ /dev/null @@ -1,18 +0,0 @@ -// +build unit - -package apppaymentsource_test - -import ( - "testing" - - apppaymentsource "github.com/lelledaniele/upaygo/payment/source" -) - -func TestNew(t *testing.T) { - r := "card_XXX" - got := apppaymentsource.New(r) - - if got.GetGatewayReference() != r { - t.Errorf("New payment source reference is incorrect, got %v want %v", got.GetGatewayReference(), r) - } -}