Skip to content

armgit / fider

Public Imported from GitHub
0

Open platform to collect and prioritize feedback

enhancement: some UX improvements + VAT (#717)

Guilherme Oenning29e27a41f70b
diff --git a/Gopkg.lock b/Gopkg.lock
index 54851ac99..8d19dcaf0 100644
--- a/Gopkg.lock
+++ b/Gopkg.lock
@@ -68,6 +68,14 @@
pruneopts = "UT"
revision = "553181ed4055278e356ce21812adb34ae487f88e"
+[[projects]]
+ digest = "1:90566a4f2f7b4e909c6b6281ff63dfaa7868457f1144d476415a84e2a36e922f"
+ name = "github.com/goenning/vat"
+ packages = ["."]
+ pruneopts = "UT"
+ revision = "4dbc96759948fa4fad4248e434601a222fa2a8a9"
+ version = "v0.1"
+
[[projects]]
branch = "master"
digest = "1:7a6377256f670508711c56c25556d639e673c0fa0f519c5a758fdcbfc8af9ac8"
@@ -302,6 +310,7 @@
"github.com/dgrijalva/jwt-go",
"github.com/disintegration/imaging",
"github.com/goenning/letteravatar",
+ "github.com/goenning/vat",
"github.com/gosimple/slug",
"github.com/joeshaw/envdecode",
"github.com/julienschmidt/httprouter",
diff --git a/Gopkg.toml b/Gopkg.toml
index 5354151c5..9d69d2915 100644
--- a/Gopkg.toml
+++ b/Gopkg.toml
@@ -29,6 +29,10 @@ ignored = ["github.com/magefile/mage/mg","github.com/magefile/mage/sh"]
branch = "master"
name = "github.com/goenning/letteravatar"
+[[constraint]]
+ version = "0.1.0"
+ name = "github.com/goenning/vat"
+
[[constraint]]
branch = "master"
name = "github.com/julienschmidt/httprouter"
diff --git a/app/actions/billing.go b/app/actions/billing.go
index 8672b057b..2a045ec49 100644
--- a/app/actions/billing.go
+++ b/app/actions/billing.go
@@ -5,7 +5,9 @@ import (
"github.com/getfider/fider/app"
"github.com/getfider/fider/app/models"
+ "github.com/getfider/fider/app/pkg/errors"
"github.com/getfider/fider/app/pkg/validate"
+ "github.com/goenning/vat"
)
// CreateEditBillingPaymentInfo is used to create/edit billing payment info
@@ -53,10 +55,6 @@ func (input *CreateEditBillingPaymentInfo) Validate(user *models.User, services
result.AddFieldFailure("addressCity", "City is required.")
}
- if input.Model.AddressState == "" {
- result.AddFieldFailure("addressState", "State/Region is required.")
- }
-
if input.Model.AddressPostalCode == "" {
result.AddFieldFailure("addressPostalCode", "Postal Code is required.")
}
@@ -90,9 +88,31 @@ func (input *CreateEditBillingPaymentInfo) Validate(user *models.User, services
}
if (isNew || isReplacing) && input.Model.Card != nil && input.Model.AddressCountry != input.Model.Card.Country {
- result.AddFieldFailure("addressCountry", "Country that doesn't match with card issue country.")
+ result.AddFieldFailure("addressCountry", "Country doesn't match with card issue country.")
} else if isUpdate && input.Model.AddressCountry != current.CardCountry {
- result.AddFieldFailure("addressCountry", "Country that doesn't match with card issue country.")
+ result.AddFieldFailure("addressCountry", "Country doesn't match with card issue country.")
+ }
+ }
+
+ if input.Model.VATNumber != "" && vat.IsEU(input.Model.AddressCountry) && (isNew || input.Model.VATNumber != current.VATNumber) {
+ valid, euCC := vat.ValidateNumberFormat(input.Model.VATNumber)
+ if !valid {
+ result.AddFieldFailure("vatNumber", "VAT Number is an invalid format.")
+ } else if euCC != input.Model.AddressCountry {
+ result.AddFieldFailure("vatNumber", "VAT Number doesn't match with selected country.")
+ } else {
+ resp, err := vat.Query(input.Model.VATNumber)
+ if err != nil {
+ if err == vat.ErrInvalidVATNumberFormat {
+ result.AddFieldFailure("vatNumber", "VAT Number is an invalid format.")
+ } else {
+ services.Logger.Error(errors.Wrap(err, "failed to validate VAT Number '%s'", input.Model.VATNumber))
+ result.AddFieldFailure("vatNumber", "We couldn't validate your VAT Number right now, please try again soon.")
+ }
+ }
+ if !resp.IsValid {
+ result.AddFieldFailure("vatNumber", "VAT Number is invalid.")
+ }
}
}
diff --git a/app/actions/billing_test.go b/app/actions/billing_test.go
index 87dc30e44..192b0cac9 100644
--- a/app/actions/billing_test.go
+++ b/app/actions/billing_test.go
@@ -16,11 +16,11 @@ func TestCreateEditBillingPaymentInfo_InvalidInput(t *testing.T) {
input *models.CreateEditBillingPaymentInfo
}{
{
- expected: []string{"card", "name", "email", "addressLine1", "addressLine2", "addressCity", "addressState", "addressPostalCode", "addressCountry"},
+ expected: []string{"card", "name", "email", "addressLine1", "addressLine2", "addressCity", "addressPostalCode", "addressCountry"},
input: &models.CreateEditBillingPaymentInfo{},
},
{
- expected: []string{"card", "email", "addressCity", "addressState", "addressPostalCode", "addressCountry"},
+ expected: []string{"card", "email", "addressCity", "addressPostalCode", "addressCountry"},
input: &models.CreateEditBillingPaymentInfo{
Name: "John",
AddressLine1: "Street 1",
@@ -30,7 +30,7 @@ func TestCreateEditBillingPaymentInfo_InvalidInput(t *testing.T) {
},
},
{
- expected: []string{"card", "email", "addressCity", "addressState", "addressPostalCode", "addressCountry"},
+ expected: []string{"card", "email", "addressCity", "addressPostalCode", "addressCountry"},
input: &models.CreateEditBillingPaymentInfo{
Name: "John",
AddressLine1: "Street 1",
@@ -77,3 +77,45 @@ func TestCreateEditBillingPaymentInfo_ValidInput(t *testing.T) {
result := action.Validate(nil, services)
ExpectSuccess(result)
}
+
+func TestCreateEditBillingPaymentInfo_VATNumber(t *testing.T) {
+ RegisterT(t)
+
+ services.Billing.SetCurrentTenant(&models.Tenant{ID: 2})
+
+ action := &actions.CreateEditBillingPaymentInfo{
+ Model: &models.CreateEditBillingPaymentInfo{
+ Name: "Jon Snow",
+ AddressLine1: "Street 1",
+ AddressLine2: "Street 2",
+ AddressCity: "New York",
+ AddressPostalCode: "12345",
+ AddressState: "NY",
+ Email: "[email protected]",
+ AddressCountry: "IE",
+ VATNumber: "IE0",
+ Card: &models.CreateEditBillingPaymentInfoCard{
+ Token: "tok_visa",
+ Country: "IE",
+ },
+ },
+ }
+ result := action.Validate(nil, services)
+ ExpectFailed(result, "vatNumber")
+
+ action.Model.VATNumber = "GB270600730"
+ result = action.Validate(nil, services)
+ ExpectFailed(result, "vatNumber")
+
+ action.Model.VATNumber = "IE6388047A"
+ result = action.Validate(nil, services)
+ ExpectFailed(result, "vatNumber")
+
+ action.Model.VATNumber = "IE6388047V"
+ result = action.Validate(nil, services)
+ ExpectSuccess(result)
+
+ action.Model.VATNumber = ""
+ result = action.Validate(nil, services)
+ ExpectSuccess(result)
+}
diff --git a/app/handlers/billing.go b/app/handlers/billing.go
index 12eb81151..97e14db56 100644
--- a/app/handlers/billing.go
+++ b/app/handlers/billing.go
@@ -9,14 +9,25 @@ import (
// BillingPage is the billing settings page
func BillingPage() web.HandlerFunc {
return func(c web.Context) error {
- _, err := c.Services().Billing.CreateCustomer("")
- if err != nil {
- return err
+ if c.Tenant().Billing.StripeCustomerID == "" {
+ _, err := c.Services().Billing.CreateCustomer("")
+ if err != nil {
+ return err
+ }
+
+ err = c.Services().Tenants.UpdateBillingSettings(c.Tenant().Billing)
+ if err != nil {
+ return err
+ }
}
- err = c.Services().Tenants.UpdateBillingSettings(c.Tenant().Billing)
- if err != nil {
- return err
+ var invoiceDue *models.UpcomingInvoice
+ if c.Tenant().Billing.StripeSubscriptionID != "" {
+ inv, err := c.Services().Billing.GetUpcomingInvoice()
+ if err != nil {
+ return c.Failure(err)
+ }
+ invoiceDue = inv
}
paymentInfo, err := c.Services().Billing.GetPaymentInfo()
@@ -38,6 +49,7 @@ func BillingPage() web.HandlerFunc {
Title: "Billing · Site Settings",
ChunkName: "Billing.page",
Data: web.Map{
+ "invoiceDue": invoiceDue,
"tenantUserCount": tenantUserCount,
"plans": plans,
"paymentInfo": paymentInfo,
diff --git a/app/middlewares/setup.go b/app/middlewares/setup.go
index 11380ad52..bcff86819 100644
--- a/app/middlewares/setup.go
+++ b/app/middlewares/setup.go
@@ -62,6 +62,7 @@ func WorkerSetup() worker.MiddlewareFunc {
}()
c.SetServices(&app.Services{
+ Logger: c.Logger(),
Tenants: postgres.NewTenantStorage(trx),
Users: postgres.NewUserStorage(trx, c),
Posts: postgres.NewPostStorage(trx, c),
@@ -150,6 +151,7 @@ func WebSetup() web.MiddlewareFunc {
c.SetActiveTransaction(trx)
c.SetServices(&app.Services{
+ Logger: c.Logger(),
Tenants: tenantStorage,
OAuth: web.NewOAuthService(oauthBaseURL, tenantStorage),
Users: postgres.NewUserStorage(trx, &c),
diff --git a/app/models/billing.go b/app/models/billing.go
index 349a5d0a0..74c888d2e 100644
--- a/app/models/billing.go
+++ b/app/models/billing.go
@@ -1,5 +1,7 @@
package models
+import "time"
+
// CreateEditBillingPaymentInfo is the input model to create or edit billing payment info
type CreateEditBillingPaymentInfo struct {
Name string `json:"name"`
@@ -11,6 +13,7 @@ type CreateEditBillingPaymentInfo struct {
AddressState string `json:"addressState"`
AddressPostalCode string `json:"addressPostalCode"`
AddressCountry string `json:"addressCountry" format:"upper"`
+ VATNumber string `json:"vatNumber"`
}
// CreateEditBillingPaymentInfoCard is the input model for a card during billing payment info update
@@ -36,6 +39,7 @@ type PaymentInfo struct {
AddressLine2 string `json:"addressLine2"`
AddressState string `json:"addressState"`
AddressPostalCode string `json:"addressPostalCode"`
+ VATNumber string `json:"vatNumber"`
}
// BillingPlan is the model for billing plan from Stripe
@@ -47,3 +51,9 @@ type BillingPlan struct {
Price int64 `json:"price"`
Interval string `json:"interval"`
}
+
+// UpcomingInvoice is the model for upcoming invoice from Stripe
+type UpcomingInvoice struct {
+ DueDate time.Time `json:"dueDate"`
+ AmountDue int64 `json:"amountDue"`
+}
diff --git a/app/models/countries.go b/app/models/countries.go
index 5247de066..1e30952dd 100644
--- a/app/models/countries.go
+++ b/app/models/countries.go
@@ -1,262 +1,269 @@
package models
+import (
+ "github.com/goenning/vat"
+)
+
// Country is a valid country within Fider
type Country struct {
Code string `json:"code"`
Name string `json:"name"`
+ IsEU bool `json:"isEU"`
+}
+
+var countries = []*Country{
+ &Country{Code: "AF", Name: "Afghanistan", IsEU: vat.IsEU("AF")},
+ &Country{Code: "AX", Name: "Åland Islands", IsEU: vat.IsEU("AX")},
+ &Country{Code: "AL", Name: "Albania", IsEU: vat.IsEU("AL")},
+ &Country{Code: "DZ", Name: "Algeria", IsEU: vat.IsEU("DZ")},
+ &Country{Code: "AS", Name: "American Samoa", IsEU: vat.IsEU("AS")},
+ &Country{Code: "AD", Name: "Andorra", IsEU: vat.IsEU("AD")},
+ &Country{Code: "AO", Name: "Angola", IsEU: vat.IsEU("AO")},
+ &Country{Code: "AI", Name: "Anguilla", IsEU: vat.IsEU("AI")},
+ &Country{Code: "AQ", Name: "Antarctica", IsEU: vat.IsEU("AQ")},
+ &Country{Code: "AG", Name: "Antigua and Barbuda", IsEU: vat.IsEU("AG")},
+ &Country{Code: "AR", Name: "Argentina", IsEU: vat.IsEU("AR")},
+ &Country{Code: "AM", Name: "Armenia", IsEU: vat.IsEU("AM")},
+ &Country{Code: "AW", Name: "Aruba", IsEU: vat.IsEU("AW")},
+ &Country{Code: "AU", Name: "Australia", IsEU: vat.IsEU("AU")},
+ &Country{Code: "AT", Name: "Austria", IsEU: vat.IsEU("AT")},
+ &Country{Code: "AZ", Name: "Azerbaijan", IsEU: vat.IsEU("AZ")},
+ &Country{Code: "BS", Name: "Bahamas", IsEU: vat.IsEU("BS")},
+ &Country{Code: "BH", Name: "Bahrain", IsEU: vat.IsEU("BH")},
+ &Country{Code: "BD", Name: "Bangladesh", IsEU: vat.IsEU("BD")},
+ &Country{Code: "BB", Name: "Barbados", IsEU: vat.IsEU("BB")},
+ &Country{Code: "BY", Name: "Belarus", IsEU: vat.IsEU("BY")},
+ &Country{Code: "BE", Name: "Belgium", IsEU: vat.IsEU("BE")},
+ &Country{Code: "BZ", Name: "Belize", IsEU: vat.IsEU("BZ")},
+ &Country{Code: "BJ", Name: "Benin", IsEU: vat.IsEU("BJ")},
+ &Country{Code: "BM", Name: "Bermuda", IsEU: vat.IsEU("BM")},
+ &Country{Code: "BT", Name: "Bhutan", IsEU: vat.IsEU("BT")},
+ &Country{Code: "BO", Name: "Bolivia, Plurinational State of", IsEU: vat.IsEU("BO")},
+ &Country{Code: "BQ", Name: "Bonaire, Sint Eustatius and Saba", IsEU: vat.IsEU("BQ")},
+ &Country{Code: "BA", Name: "Bosnia and Herzegovina", IsEU: vat.IsEU("BA")},
+ &Country{Code: "BW", Name: "Botswana", IsEU: vat.IsEU("BW")},
+ &Country{Code: "BV", Name: "Bouvet Island", IsEU: vat.IsEU("BV")},
+ &Country{Code: "BR", Name: "Brazil", IsEU: vat.IsEU("BR")},
+ &Country{Code: "IO", Name: "British Indian Ocean Territory", IsEU: vat.IsEU("IO")},
+ &Country{Code: "BN", Name: "Brunei Darussalam", IsEU: vat.IsEU("BN")},
+ &Country{Code: "BG", Name: "Bulgaria", IsEU: vat.IsEU("BG")},
+ &Country{Code: "BF", Name: "Burkina Faso", IsEU: vat.IsEU("BF")},
+ &Country{Code: "BI", Name: "Burundi", IsEU: vat.IsEU("BI")},
+ &Country{Code: "KH", Name: "Cambodia", IsEU: vat.IsEU("KH")},
+ &Country{Code: "CM", Name: "Cameroon", IsEU: vat.IsEU("CM")},
+ &Country{Code: "CA", Name: "Canada", IsEU: vat.IsEU("CA")},
+ &Country{Code: "CV", Name: "Cape Verde", IsEU: vat.IsEU("CV")},
+ &Country{Code: "KY", Name: "Cayman Islands", IsEU: vat.IsEU("KY")},
+ &Country{Code: "CF", Name: "Central African Republic", IsEU: vat.IsEU("CF")},
+ &Country{Code: "TD", Name: "Chad", IsEU: vat.IsEU("TD")},
+ &Country{Code: "CL", Name: "Chile", IsEU: vat.IsEU("CL")},
+ &Country{Code: "CN", Name: "China", IsEU: vat.IsEU("CN")},
+ &Country{Code: "CX", Name: "Christmas Island", IsEU: vat.IsEU("CX")},
+ &Country{Code: "CC", Name: "Cocos (Keeling) Islands", IsEU: vat.IsEU("CC")},
+ &Country{Code: "CO", Name: "Colombia", IsEU: vat.IsEU("CO")},
+ &Country{Code: "KM", Name: "Comoros", IsEU: vat.IsEU("KM")},
+ &Country{Code: "CG", Name: "Congo", IsEU: vat.IsEU("CG")},
+ &Country{Code: "CD", Name: "Congo, the Democratic Republic of the", IsEU: vat.IsEU("CD")},
+ &Country{Code: "CK", Name: "Cook Islands", IsEU: vat.IsEU("CK")},
+ &Country{Code: "CR", Name: "Costa Rica", IsEU: vat.IsEU("CR")},
+ &Country{Code: "CI", Name: "Côte d'Ivoire", IsEU: vat.IsEU("CI")},
+ &Country{Code: "HR", Name: "Croatia", IsEU: vat.IsEU("HR")},
+ &Country{Code: "CU", Name: "Cuba", IsEU: vat.IsEU("CU")},
+ &Country{Code: "CW", Name: "Curaçao", IsEU: vat.IsEU("CW")},
+ &Country{Code: "CY", Name: "Cyprus", IsEU: vat.IsEU("CY")},
+ &Country{Code: "CZ", Name: "Czech Republic", IsEU: vat.IsEU("CZ")},
+ &Country{Code: "DK", Name: "Denmark", IsEU: vat.IsEU("DK")},
+ &Country{Code: "DJ", Name: "Djibouti", IsEU: vat.IsEU("DJ")},
+ &Country{Code: "DM", Name: "Dominica", IsEU: vat.IsEU("DM")},
+ &Country{Code: "DO", Name: "Dominican Republic", IsEU: vat.IsEU("DO")},
+ &Country{Code: "EC", Name: "Ecuador", IsEU: vat.IsEU("EC")},
+ &Country{Code: "EG", Name: "Egypt", IsEU: vat.IsEU("EG")},
+ &Country{Code: "SV", Name: "El Salvador", IsEU: vat.IsEU("SV")},
+ &Country{Code: "GQ", Name: "Equatorial Guinea", IsEU: vat.IsEU("GQ")},
+ &Country{Code: "ER", Name: "Eritrea", IsEU: vat.IsEU("ER")},
+ &Country{Code: "EE", Name: "Estonia", IsEU: vat.IsEU("EE")},
+ &Country{Code: "ET", Name: "Ethiopia", IsEU: vat.IsEU("ET")},
+ &Country{Code: "FK", Name: "Falkland Islands (Malvinas)", IsEU: vat.IsEU("FK")},
+ &Country{Code: "FO", Name: "Faroe Islands", IsEU: vat.IsEU("FO")},
+ &Country{Code: "FJ", Name: "Fiji", IsEU: vat.IsEU("FJ")},
+ &Country{Code: "FI", Name: "Finland", IsEU: vat.IsEU("FI")},
+ &Country{Code: "FR", Name: "France", IsEU: vat.IsEU("FR")},
+ &Country{Code: "GF", Name: "French Guiana", IsEU: vat.IsEU("GF")},
+ &Country{Code: "PF", Name: "French Polynesia", IsEU: vat.IsEU("PF")},
+ &Country{Code: "TF", Name: "French Southern Territories", IsEU: vat.IsEU("TF")},
+ &Country{Code: "GA", Name: "Gabon", IsEU: vat.IsEU("GA")},
+ &Country{Code: "GM", Name: "Gambia", IsEU: vat.IsEU("GM")},
+ &Country{Code: "GE", Name: "Georgia", IsEU: vat.IsEU("GE")},
+ &Country{Code: "DE", Name: "Germany", IsEU: vat.IsEU("DE")},
+ &Country{Code: "GH", Name: "Ghana", IsEU: vat.IsEU("GH")},
+ &Country{Code: "GI", Name: "Gibraltar", IsEU: vat.IsEU("GI")},
+ &Country{Code: "GR", Name: "Greece", IsEU: vat.IsEU("GR")},
+ &Country{Code: "GL", Name: "Greenland", IsEU: vat.IsEU("GL")},
+ &Country{Code: "GD", Name: "Grenada", IsEU: vat.IsEU("GD")},
+ &Country{Code: "GP", Name: "Guadeloupe", IsEU: vat.IsEU("GP")},
+ &Country{Code: "GU", Name: "Guam", IsEU: vat.IsEU("GU")},
+ &Country{Code: "GT", Name: "Guatemala", IsEU: vat.IsEU("GT")},
+ &Country{Code: "GG", Name: "Guernsey", IsEU: vat.IsEU("GG")},
+ &Country{Code: "GN", Name: "Guinea", IsEU: vat.IsEU("GN")},
+ &Country{Code: "GW", Name: "Guinea-Bissau", IsEU: vat.IsEU("GW")},
+ &Country{Code: "GY", Name: "Guyana", IsEU: vat.IsEU("GY")},
+ &Country{Code: "HT", Name: "Haiti", IsEU: vat.IsEU("HT")},
+ &Country{Code: "HM", Name: "Heard Island and McDonald Islands", IsEU: vat.IsEU("HM")},
+ &Country{Code: "VA", Name: "Holy See (Vatican City State)", IsEU: vat.IsEU("VA")},
+ &Country{Code: "HN", Name: "Honduras", IsEU: vat.IsEU("HN")},
+ &Country{Code: "HK", Name: "Hong Kong", IsEU: vat.IsEU("HK")},
+ &Country{Code: "HU", Name: "Hungary", IsEU: vat.IsEU("HU")},
+ &Country{Code: "IS", Name: "Iceland", IsEU: vat.IsEU("IS")},
+ &Country{Code: "IN", Name: "India", IsEU: vat.IsEU("IN")},
+ &Country{Code: "ID", Name: "Indonesia", IsEU: vat.IsEU("ID")},
+ &Country{Code: "IR", Name: "Iran, Islamic Republic of", IsEU: vat.IsEU("IR")},
+ &Country{Code: "IQ", Name: "Iraq", IsEU: vat.IsEU("IQ")},
+ &Country{Code: "IE", Name: "Ireland", IsEU: vat.IsEU("IE")},
+ &Country{Code: "IM", Name: "Isle of Man", IsEU: vat.IsEU("IM")},
+ &Country{Code: "IL", Name: "Israel", IsEU: vat.IsEU("IL")},
+ &Country{Code: "IT", Name: "Italy", IsEU: vat.IsEU("IT")},
+ &Country{Code: "JM", Name: "Jamaica", IsEU: vat.IsEU("JM")},
+ &Country{Code: "JP", Name: "Japan", IsEU: vat.IsEU("JP")},
+ &Country{Code: "JE", Name: "Jersey", IsEU: vat.IsEU("JE")},
+ &Country{Code: "JO", Name: "Jordan", IsEU: vat.IsEU("JO")},
+ &Country{Code: "KZ", Name: "Kazakhstan", IsEU: vat.IsEU("KZ")},
+ &Country{Code: "KE", Name: "Kenya", IsEU: vat.IsEU("KE")},
+ &Country{Code: "KI", Name: "Kiribati", IsEU: vat.IsEU("KI")},
+ &Country{Code: "KP", Name: "Korea, Democratic People's Republic of", IsEU: vat.IsEU("KP")},
+ &Country{Code: "KR", Name: "Korea, Republic of", IsEU: vat.IsEU("KR")},
+ &Country{Code: "KW", Name: "Kuwait", IsEU: vat.IsEU("KW")},
+ &Country{Code: "KG", Name: "Kyrgyzstan", IsEU: vat.IsEU("KG")},
+ &Country{Code: "LA", Name: "Lao People's Democratic Republic", IsEU: vat.IsEU("LA")},
+ &Country{Code: "LV", Name: "Latvia", IsEU: vat.IsEU("LV")},
+ &Country{Code: "LB", Name: "Lebanon", IsEU: vat.IsEU("LB")},
+ &Country{Code: "LS", Name: "Lesotho", IsEU: vat.IsEU("LS")},
+ &Country{Code: "LR", Name: "Liberia", IsEU: vat.IsEU("LR")},
+ &Country{Code: "LY", Name: "Libya", IsEU: vat.IsEU("LY")},
+ &Country{Code: "LI", Name: "Liechtenstein", IsEU: vat.IsEU("LI")},
+ &Country{Code: "LT", Name: "Lithuania", IsEU: vat.IsEU("LT")},
+ &Country{Code: "LU", Name: "Luxembourg", IsEU: vat.IsEU("LU")},
+ &Country{Code: "MO", Name: "Macao", IsEU: vat.IsEU("MO")},
+ &Country{Code: "MK", Name: "Macedonia, the former Yugoslav Republic of", IsEU: vat.IsEU("MK")},
+ &Country{Code: "MG", Name: "Madagascar", IsEU: vat.IsEU("MG")},
+ &Country{Code: "MW", Name: "Malawi", IsEU: vat.IsEU("MW")},
+ &Country{Code: "MY", Name: "Malaysia", IsEU: vat.IsEU("MY")},
+ &Country{Code: "MV", Name: "Maldives", IsEU: vat.IsEU("MV")},
+ &Country{Code: "ML", Name: "Mali", IsEU: vat.IsEU("ML")},
+ &Country{Code: "MT", Name: "Malta", IsEU: vat.IsEU("MT")},
+ &Country{Code: "MH", Name: "Marshall Islands", IsEU: vat.IsEU("MH")},
+ &Country{Code: "MQ", Name: "Martinique", IsEU: vat.IsEU("MQ")},
+ &Country{Code: "MR", Name: "Mauritania", IsEU: vat.IsEU("MR")},
+ &Country{Code: "MU", Name: "Mauritius", IsEU: vat.IsEU("MU")},
+ &Country{Code: "YT", Name: "Mayotte", IsEU: vat.IsEU("YT")},
+ &Country{Code: "MX", Name: "Mexico", IsEU: vat.IsEU("MX")},
+ &Country{Code: "FM", Name: "Micronesia, Federated States of", IsEU: vat.IsEU("FM")},
+ &Country{Code: "MD", Name: "Moldova, Republic of", IsEU: vat.IsEU("MD")},
+ &Country{Code: "MC", Name: "Monaco", IsEU: vat.IsEU("MC")},
+ &Country{Code: "MN", Name: "Mongolia", IsEU: vat.IsEU("MN")},
+ &Country{Code: "ME", Name: "Montenegro", IsEU: vat.IsEU("ME")},
+ &Country{Code: "MS", Name: "Montserrat", IsEU: vat.IsEU("MS")},
+ &Country{Code: "MA", Name: "Morocco", IsEU: vat.IsEU("MA")},
+ &Country{Code: "MZ", Name: "Mozambique", IsEU: vat.IsEU("MZ")},
+ &Country{Code: "MM", Name: "Myanmar", IsEU: vat.IsEU("MM")},
+ &Country{Code: "NA", Name: "Namibia", IsEU: vat.IsEU("NA")},
+ &Country{Code: "NR", Name: "Nauru", IsEU: vat.IsEU("NR")},
+ &Country{Code: "NP", Name: "Nepal", IsEU: vat.IsEU("NP")},
+ &Country{Code: "NL", Name: "Netherlands", IsEU: vat.IsEU("NL")},
+ &Country{Code: "NC", Name: "New Caledonia", IsEU: vat.IsEU("NC")},
+ &Country{Code: "NZ", Name: "New Zealand", IsEU: vat.IsEU("NZ")},
+ &Country{Code: "NI", Name: "Nicaragua", IsEU: vat.IsEU("NI")},
+ &Country{Code: "NE", Name: "Niger", IsEU: vat.IsEU("NE")},
+ &Country{Code: "NG", Name: "Nigeria", IsEU: vat.IsEU("NG")},
+ &Country{Code: "NU", Name: "Niue", IsEU: vat.IsEU("NU")},
+ &Country{Code: "NF", Name: "Norfolk Island", IsEU: vat.IsEU("NF")},
+ &Country{Code: "MP", Name: "Northern Mariana Islands", IsEU: vat.IsEU("MP")},
+ &Country{Code: "NO", Name: "Norway", IsEU: vat.IsEU("NO")},
+ &Country{Code: "OM", Name: "Oman", IsEU: vat.IsEU("OM")},
+ &Country{Code: "PK", Name: "Pakistan", IsEU: vat.IsEU("PK")},
+ &Country{Code: "PW", Name: "Palau", IsEU: vat.IsEU("PW")},
+ &Country{Code: "PS", Name: "Palestinian Territory, Occupied", IsEU: vat.IsEU("PS")},
+ &Country{Code: "PA", Name: "Panama", IsEU: vat.IsEU("PA")},
+ &Country{Code: "PG", Name: "Papua New Guinea", IsEU: vat.IsEU("PG")},
+ &Country{Code: "PY", Name: "Paraguay", IsEU: vat.IsEU("PY")},
+ &Country{Code: "PE", Name: "Peru", IsEU: vat.IsEU("PE")},
+ &Country{Code: "PH", Name: "Philippines", IsEU: vat.IsEU("PH")},
+ &Country{Code: "PN", Name: "Pitcairn", IsEU: vat.IsEU("PN")},
+ &Country{Code: "PL", Name: "Poland", IsEU: vat.IsEU("PL")},
+ &Country{Code: "PT", Name: "Portugal", IsEU: vat.IsEU("PT")},
+ &Country{Code: "PR", Name: "Puerto Rico", IsEU: vat.IsEU("PR")},
+ &Country{Code: "QA", Name: "Qatar", IsEU: vat.IsEU("QA")},
+ &Country{Code: "RE", Name: "Réunion", IsEU: vat.IsEU("RE")},
+ &Country{Code: "RO", Name: "Romania", IsEU: vat.IsEU("RO")},
+ &Country{Code: "RU", Name: "Russian Federation", IsEU: vat.IsEU("RU")},
+ &Country{Code: "RW", Name: "Rwanda", IsEU: vat.IsEU("RW")},
+ &Country{Code: "BL", Name: "Saint Barthélemy", IsEU: vat.IsEU("BL")},
+ &Country{Code: "SH", Name: "Saint Helena, Ascension and Tristan da Cunha", IsEU: vat.IsEU("SH")},
+ &Country{Code: "KN", Name: "Saint Kitts and Nevis", IsEU: vat.IsEU("KN")},
+ &Country{Code: "LC", Name: "Saint Lucia", IsEU: vat.IsEU("LC")},
+ &Country{Code: "MF", Name: "Saint Martin (French part)", IsEU: vat.IsEU("MF")},
+ &Country{Code: "PM", Name: "Saint Pierre and Miquelon", IsEU: vat.IsEU("PM")},
+ &Country{Code: "VC", Name: "Saint Vincent and the Grenadines", IsEU: vat.IsEU("VC")},
+ &Country{Code: "WS", Name: "Samoa", IsEU: vat.IsEU("WS")},
+ &Country{Code: "SM", Name: "San Marino", IsEU: vat.IsEU("SM")},
+ &Country{Code: "ST", Name: "Sao Tome and Principe", IsEU: vat.IsEU("ST")},
+ &Country{Code: "SA", Name: "Saudi Arabia", IsEU: vat.IsEU("SA")},
+ &Country{Code: "SN", Name: "Senegal", IsEU: vat.IsEU("SN")},
+ &Country{Code: "RS", Name: "Serbia", IsEU: vat.IsEU("RS")},
+ &Country{Code: "SC", Name: "Seychelles", IsEU: vat.IsEU("SC")},
+ &Country{Code: "SL", Name: "Sierra Leone", IsEU: vat.IsEU("SL")},
+ &Country{Code: "SG", Name: "Singapore", IsEU: vat.IsEU("SG")},
+ &Country{Code: "SX", Name: "Sint Maarten (Dutch part)", IsEU: vat.IsEU("SX")},
+ &Country{Code: "SK", Name: "Slovakia", IsEU: vat.IsEU("SK")},
+ &Country{Code: "SI", Name: "Slovenia", IsEU: vat.IsEU("SI")},
+ &Country{Code: "SB", Name: "Solomon Islands", IsEU: vat.IsEU("SB")},
+ &Country{Code: "SO", Name: "Somalia", IsEU: vat.IsEU("SO")},
+ &Country{Code: "ZA", Name: "South Africa", IsEU: vat.IsEU("ZA")},
+ &Country{Code: "GS", Name: "South Georgia and the South Sandwich Islands", IsEU: vat.IsEU("GS")},
+ &Country{Code: "SS", Name: "South Sudan", IsEU: vat.IsEU("SS")},
+ &Country{Code: "ES", Name: "Spain", IsEU: vat.IsEU("ES")},
+ &Country{Code: "LK", Name: "Sri Lanka", IsEU: vat.IsEU("LK")},
+ &Country{Code: "SD", Name: "Sudan", IsEU: vat.IsEU("SD")},
+ &Country{Code: "SR", Name: "Suriname", IsEU: vat.IsEU("SR")},
+ &Country{Code: "SJ", Name: "Svalbard and Jan Mayen", IsEU: vat.IsEU("SJ")},
+ &Country{Code: "SZ", Name: "Swaziland", IsEU: vat.IsEU("SZ")},
+ &Country{Code: "SE", Name: "Sweden", IsEU: vat.IsEU("SE")},
+ &Country{Code: "CH", Name: "Switzerland", IsEU: vat.IsEU("CH")},
+ &Country{Code: "SY", Name: "Syrian Arab Republic", IsEU: vat.IsEU("SY")},
+ &Country{Code: "TW", Name: "Taiwan, Province of China", IsEU: vat.IsEU("TW")},
+ &Country{Code: "TJ", Name: "Tajikistan", IsEU: vat.IsEU("TJ")},
+ &Country{Code: "TZ", Name: "Tanzania, United Republic of", IsEU: vat.IsEU("TZ")},
+ &Country{Code: "TH", Name: "Thailand", IsEU: vat.IsEU("TH")},
+ &Country{Code: "TL", Name: "Timor-Leste", IsEU: vat.IsEU("TL")},
+ &Country{Code: "TG", Name: "Togo", IsEU: vat.IsEU("TG")},
+ &Country{Code: "TK", Name: "Tokelau", IsEU: vat.IsEU("TK")},
+ &Country{Code: "TO", Name: "Tonga", IsEU: vat.IsEU("TO")},
+ &Country{Code: "TT", Name: "Trinidad and Tobago", IsEU: vat.IsEU("TT")},
+ &Country{Code: "TN", Name: "Tunisia", IsEU: vat.IsEU("TN")},
+ &Country{Code: "TR", Name: "Turkey", IsEU: vat.IsEU("TR")},
+ &Country{Code: "TM", Name: "Turkmenistan", IsEU: vat.IsEU("TM")},
+ &Country{Code: "TC", Name: "Turks and Caicos Islands", IsEU: vat.IsEU("TC")},
+ &Country{Code: "TV", Name: "Tuvalu", IsEU: vat.IsEU("TV")},
+ &Country{Code: "UG", Name: "Uganda", IsEU: vat.IsEU("UG")},
+ &Country{Code: "UA", Name: "Ukraine", IsEU: vat.IsEU("UA")},
+ &Country{Code: "AE", Name: "United Arab Emirates", IsEU: vat.IsEU("AE")},
+ &Country{Code: "GB", Name: "United Kingdom", IsEU: vat.IsEU("GB")},
+ &Country{Code: "US", Name: "United States", IsEU: vat.IsEU("US")},
+ &Country{Code: "UM", Name: "United States Minor Outlying Islands", IsEU: vat.IsEU("UM")},
+ &Country{Code: "UY", Name: "Uruguay", IsEU: vat.IsEU("UY")},
+ &Country{Code: "UZ", Name: "Uzbekistan", IsEU: vat.IsEU("UZ")},
+ &Country{Code: "VU", Name: "Vanuatu", IsEU: vat.IsEU("VU")},
+ &Country{Code: "VE", Name: "Venezuela, Bolivarian Republic of", IsEU: vat.IsEU("VE")},
+ &Country{Code: "VN", Name: "Viet Nam", IsEU: vat.IsEU("VN")},
+ &Country{Code: "VG", Name: "Virgin Islands, British", IsEU: vat.IsEU("VG")},
+ &Country{Code: "VI", Name: "Virgin Islands, U.S.", IsEU: vat.IsEU("VI")},
+ &Country{Code: "WF", Name: "Wallis and Futuna", IsEU: vat.IsEU("WF")},
+ &Country{Code: "EH", Name: "Western Sahara", IsEU: vat.IsEU("EH")},
+ &Country{Code: "YE", Name: "Yemen", IsEU: vat.IsEU("YE")},
+ &Country{Code: "ZM", Name: "Zambia", IsEU: vat.IsEU("ZM")},
+ &Country{Code: "ZW", Name: "Zimbabwe", IsEU: vat.IsEU("ZW")},
}
// GetAllCountries returns a list of all known countries
func GetAllCountries() []*Country {
- return []*Country{
- &Country{Code: "AF", Name: "Afghanistan"},
- &Country{Code: "AX", Name: "Åland Islands"},
- &Country{Code: "AL", Name: "Albania"},
- &Country{Code: "DZ", Name: "Algeria"},
- &Country{Code: "AS", Name: "American Samoa"},
- &Country{Code: "AD", Name: "Andorra"},
- &Country{Code: "AO", Name: "Angola"},
- &Country{Code: "AI", Name: "Anguilla"},
- &Country{Code: "AQ", Name: "Antarctica"},
- &Country{Code: "AG", Name: "Antigua and Barbuda"},
- &Country{Code: "AR", Name: "Argentina"},
- &Country{Code: "AM", Name: "Armenia"},
- &Country{Code: "AW", Name: "Aruba"},
- &Country{Code: "AU", Name: "Australia"},
- &Country{Code: "AT", Name: "Austria"},
- &Country{Code: "AZ", Name: "Azerbaijan"},
- &Country{Code: "BS", Name: "Bahamas"},
- &Country{Code: "BH", Name: "Bahrain"},
- &Country{Code: "BD", Name: "Bangladesh"},
- &Country{Code: "BB", Name: "Barbados"},
- &Country{Code: "BY", Name: "Belarus"},
- &Country{Code: "BE", Name: "Belgium"},
- &Country{Code: "BZ", Name: "Belize"},
- &Country{Code: "BJ", Name: "Benin"},
- &Country{Code: "BM", Name: "Bermuda"},
- &Country{Code: "BT", Name: "Bhutan"},
- &Country{Code: "BO", Name: "Bolivia, Plurinational State of"},
- &Country{Code: "BQ", Name: "Bonaire, Sint Eustatius and Saba"},
- &Country{Code: "BA", Name: "Bosnia and Herzegovina"},
- &Country{Code: "BW", Name: "Botswana"},
- &Country{Code: "BV", Name: "Bouvet Island"},
- &Country{Code: "BR", Name: "Brazil"},
- &Country{Code: "IO", Name: "British Indian Ocean Territory"},
- &Country{Code: "BN", Name: "Brunei Darussalam"},
- &Country{Code: "BG", Name: "Bulgaria"},
- &Country{Code: "BF", Name: "Burkina Faso"},
- &Country{Code: "BI", Name: "Burundi"},
- &Country{Code: "KH", Name: "Cambodia"},
- &Country{Code: "CM", Name: "Cameroon"},
- &Country{Code: "CA", Name: "Canada"},
- &Country{Code: "CV", Name: "Cape Verde"},
- &Country{Code: "KY", Name: "Cayman Islands"},
- &Country{Code: "CF", Name: "Central African Republic"},
- &Country{Code: "TD", Name: "Chad"},
- &Country{Code: "CL", Name: "Chile"},
- &Country{Code: "CN", Name: "China"},
- &Country{Code: "CX", Name: "Christmas Island"},
- &Country{Code: "CC", Name: "Cocos (Keeling) Islands"},
- &Country{Code: "CO", Name: "Colombia"},
- &Country{Code: "KM", Name: "Comoros"},
- &Country{Code: "CG", Name: "Congo"},
- &Country{Code: "CD", Name: "Congo, the Democratic Republic of the"},
- &Country{Code: "CK", Name: "Cook Islands"},
- &Country{Code: "CR", Name: "Costa Rica"},
- &Country{Code: "CI", Name: "Côte d'Ivoire"},
- &Country{Code: "HR", Name: "Croatia"},
- &Country{Code: "CU", Name: "Cuba"},
- &Country{Code: "CW", Name: "Curaçao"},
- &Country{Code: "CY", Name: "Cyprus"},
- &Country{Code: "CZ", Name: "Czech Republic"},
- &Country{Code: "DK", Name: "Denmark"},
- &Country{Code: "DJ", Name: "Djibouti"},
- &Country{Code: "DM", Name: "Dominica"},
- &Country{Code: "DO", Name: "Dominican Republic"},
- &Country{Code: "EC", Name: "Ecuador"},
- &Country{Code: "EG", Name: "Egypt"},
- &Country{Code: "SV", Name: "El Salvador"},
- &Country{Code: "GQ", Name: "Equatorial Guinea"},
- &Country{Code: "ER", Name: "Eritrea"},
- &Country{Code: "EE", Name: "Estonia"},
- &Country{Code: "ET", Name: "Ethiopia"},
- &Country{Code: "FK", Name: "Falkland Islands (Malvinas)"},
- &Country{Code: "FO", Name: "Faroe Islands"},
- &Country{Code: "FJ", Name: "Fiji"},
- &Country{Code: "FI", Name: "Finland"},
- &Country{Code: "FR", Name: "France"},
- &Country{Code: "GF", Name: "French Guiana"},
- &Country{Code: "PF", Name: "French Polynesia"},
- &Country{Code: "TF", Name: "French Southern Territories"},
- &Country{Code: "GA", Name: "Gabon"},
- &Country{Code: "GM", Name: "Gambia"},
- &Country{Code: "GE", Name: "Georgia"},
- &Country{Code: "DE", Name: "Germany"},
- &Country{Code: "GH", Name: "Ghana"},
- &Country{Code: "GI", Name: "Gibraltar"},
- &Country{Code: "GR", Name: "Greece"},
- &Country{Code: "GL", Name: "Greenland"},
- &Country{Code: "GD", Name: "Grenada"},
- &Country{Code: "GP", Name: "Guadeloupe"},
- &Country{Code: "GU", Name: "Guam"},
- &Country{Code: "GT", Name: "Guatemala"},
- &Country{Code: "GG", Name: "Guernsey"},
- &Country{Code: "GN", Name: "Guinea"},
- &Country{Code: "GW", Name: "Guinea-Bissau"},
- &Country{Code: "GY", Name: "Guyana"},
- &Country{Code: "HT", Name: "Haiti"},
- &Country{Code: "HM", Name: "Heard Island and McDonald Islands"},
- &Country{Code: "VA", Name: "Holy See (Vatican City State)"},
- &Country{Code: "HN", Name: "Honduras"},
- &Country{Code: "HK", Name: "Hong Kong"},
- &Country{Code: "HU", Name: "Hungary"},
- &Country{Code: "IS", Name: "Iceland"},
- &Country{Code: "IN", Name: "India"},
- &Country{Code: "ID", Name: "Indonesia"},
- &Country{Code: "IR", Name: "Iran, Islamic Republic of"},
- &Country{Code: "IQ", Name: "Iraq"},
- &Country{Code: "IE", Name: "Ireland"},
- &Country{Code: "IM", Name: "Isle of Man"},
- &Country{Code: "IL", Name: "Israel"},
- &Country{Code: "IT", Name: "Italy"},
- &Country{Code: "JM", Name: "Jamaica"},
- &Country{Code: "JP", Name: "Japan"},
- &Country{Code: "JE", Name: "Jersey"},
- &Country{Code: "JO", Name: "Jordan"},
- &Country{Code: "KZ", Name: "Kazakhstan"},
- &Country{Code: "KE", Name: "Kenya"},
- &Country{Code: "KI", Name: "Kiribati"},
- &Country{Code: "KP", Name: "Korea, Democratic People's Republic of"},
- &Country{Code: "KR", Name: "Korea, Republic of"},
- &Country{Code: "KW", Name: "Kuwait"},
- &Country{Code: "KG", Name: "Kyrgyzstan"},
- &Country{Code: "LA", Name: "Lao People's Democratic Republic"},
- &Country{Code: "LV", Name: "Latvia"},
- &Country{Code: "LB", Name: "Lebanon"},
- &Country{Code: "LS", Name: "Lesotho"},
- &Country{Code: "LR", Name: "Liberia"},
- &Country{Code: "LY", Name: "Libya"},
- &Country{Code: "LI", Name: "Liechtenstein"},
- &Country{Code: "LT", Name: "Lithuania"},
- &Country{Code: "LU", Name: "Luxembourg"},
- &Country{Code: "MO", Name: "Macao"},
- &Country{Code: "MK", Name: "Macedonia, the former Yugoslav Republic of"},
- &Country{Code: "MG", Name: "Madagascar"},
- &Country{Code: "MW", Name: "Malawi"},
- &Country{Code: "MY", Name: "Malaysia"},
- &Country{Code: "MV", Name: "Maldives"},
- &Country{Code: "ML", Name: "Mali"},
- &Country{Code: "MT", Name: "Malta"},
- &Country{Code: "MH", Name: "Marshall Islands"},
- &Country{Code: "MQ", Name: "Martinique"},
- &Country{Code: "MR", Name: "Mauritania"},
- &Country{Code: "MU", Name: "Mauritius"},
- &Country{Code: "YT", Name: "Mayotte"},
- &Country{Code: "MX", Name: "Mexico"},
- &Country{Code: "FM", Name: "Micronesia, Federated States of"},
- &Country{Code: "MD", Name: "Moldova, Republic of"},
- &Country{Code: "MC", Name: "Monaco"},
- &Country{Code: "MN", Name: "Mongolia"},
- &Country{Code: "ME", Name: "Montenegro"},
- &Country{Code: "MS", Name: "Montserrat"},
- &Country{Code: "MA", Name: "Morocco"},
- &Country{Code: "MZ", Name: "Mozambique"},
- &Country{Code: "MM", Name: "Myanmar"},
- &Country{Code: "NA", Name: "Namibia"},
- &Country{Code: "NR", Name: "Nauru"},
- &Country{Code: "NP", Name: "Nepal"},
- &Country{Code: "NL", Name: "Netherlands"},
- &Country{Code: "NC", Name: "New Caledonia"},
- &Country{Code: "NZ", Name: "New Zealand"},
- &Country{Code: "NI", Name: "Nicaragua"},
- &Country{Code: "NE", Name: "Niger"},
- &Country{Code: "NG", Name: "Nigeria"},
- &Country{Code: "NU", Name: "Niue"},
- &Country{Code: "NF", Name: "Norfolk Island"},
- &Country{Code: "MP", Name: "Northern Mariana Islands"},
- &Country{Code: "NO", Name: "Norway"},
- &Country{Code: "OM", Name: "Oman"},
- &Country{Code: "PK", Name: "Pakistan"},
- &Country{Code: "PW", Name: "Palau"},
- &Country{Code: "PS", Name: "Palestinian Territory, Occupied"},
- &Country{Code: "PA", Name: "Panama"},
- &Country{Code: "PG", Name: "Papua New Guinea"},
- &Country{Code: "PY", Name: "Paraguay"},
- &Country{Code: "PE", Name: "Peru"},
- &Country{Code: "PH", Name: "Philippines"},
- &Country{Code: "PN", Name: "Pitcairn"},
- &Country{Code: "PL", Name: "Poland"},
- &Country{Code: "PT", Name: "Portugal"},
- &Country{Code: "PR", Name: "Puerto Rico"},
- &Country{Code: "QA", Name: "Qatar"},
- &Country{Code: "RE", Name: "Réunion"},
- &Country{Code: "RO", Name: "Romania"},
- &Country{Code: "RU", Name: "Russian Federation"},
- &Country{Code: "RW", Name: "Rwanda"},
- &Country{Code: "BL", Name: "Saint Barthélemy"},
- &Country{Code: "SH", Name: "Saint Helena, Ascension and Tristan da Cunha"},
- &Country{Code: "KN", Name: "Saint Kitts and Nevis"},
- &Country{Code: "LC", Name: "Saint Lucia"},
- &Country{Code: "MF", Name: "Saint Martin (French part)"},
- &Country{Code: "PM", Name: "Saint Pierre and Miquelon"},
- &Country{Code: "VC", Name: "Saint Vincent and the Grenadines"},
- &Country{Code: "WS", Name: "Samoa"},
- &Country{Code: "SM", Name: "San Marino"},
- &Country{Code: "ST", Name: "Sao Tome and Principe"},
- &Country{Code: "SA", Name: "Saudi Arabia"},
- &Country{Code: "SN", Name: "Senegal"},
- &Country{Code: "RS", Name: "Serbia"},
- &Country{Code: "SC", Name: "Seychelles"},
- &Country{Code: "SL", Name: "Sierra Leone"},
- &Country{Code: "SG", Name: "Singapore"},
- &Country{Code: "SX", Name: "Sint Maarten (Dutch part)"},
- &Country{Code: "SK", Name: "Slovakia"},
- &Country{Code: "SI", Name: "Slovenia"},
- &Country{Code: "SB", Name: "Solomon Islands"},
- &Country{Code: "SO", Name: "Somalia"},
- &Country{Code: "ZA", Name: "South Africa"},
- &Country{Code: "GS", Name: "South Georgia and the South Sandwich Islands"},
- &Country{Code: "SS", Name: "South Sudan"},
- &Country{Code: "ES", Name: "Spain"},
- &Country{Code: "LK", Name: "Sri Lanka"},
- &Country{Code: "SD", Name: "Sudan"},
- &Country{Code: "SR", Name: "Suriname"},
- &Country{Code: "SJ", Name: "Svalbard and Jan Mayen"},
- &Country{Code: "SZ", Name: "Swaziland"},
- &Country{Code: "SE", Name: "Sweden"},
- &Country{Code: "CH", Name: "Switzerland"},
- &Country{Code: "SY", Name: "Syrian Arab Republic"},
- &Country{Code: "TW", Name: "Taiwan, Province of China"},
- &Country{Code: "TJ", Name: "Tajikistan"},
- &Country{Code: "TZ", Name: "Tanzania, United Republic of"},
- &Country{Code: "TH", Name: "Thailand"},
- &Country{Code: "TL", Name: "Timor-Leste"},
- &Country{Code: "TG", Name: "Togo"},
- &Country{Code: "TK", Name: "Tokelau"},
- &Country{Code: "TO", Name: "Tonga"},
- &Country{Code: "TT", Name: "Trinidad and Tobago"},
- &Country{Code: "TN", Name: "Tunisia"},
- &Country{Code: "TR", Name: "Turkey"},
- &Country{Code: "TM", Name: "Turkmenistan"},
- &Country{Code: "TC", Name: "Turks and Caicos Islands"},
- &Country{Code: "TV", Name: "Tuvalu"},
- &Country{Code: "UG", Name: "Uganda"},
- &Country{Code: "UA", Name: "Ukraine"},
- &Country{Code: "AE", Name: "United Arab Emirates"},
- &Country{Code: "GB", Name: "United Kingdom"},
- &Country{Code: "US", Name: "United States"},
- &Country{Code: "UM", Name: "United States Minor Outlying Islands"},
- &Country{Code: "UY", Name: "Uruguay"},
- &Country{Code: "UZ", Name: "Uzbekistan"},
- &Country{Code: "VU", Name: "Vanuatu"},
- &Country{Code: "VE", Name: "Venezuela, Bolivarian Republic of"},
- &Country{Code: "VN", Name: "Viet Nam"},
- &Country{Code: "VG", Name: "Virgin Islands, British"},
- &Country{Code: "VI", Name: "Virgin Islands, U.S."},
- &Country{Code: "WF", Name: "Wallis and Futuna"},
- &Country{Code: "EH", Name: "Western Sahara"},
- &Country{Code: "YE", Name: "Yemen"},
- &Country{Code: "ZM", Name: "Zambia"},
- &Country{Code: "ZW", Name: "Zimbabwe"},
- }
+ return countries
}
diff --git a/app/pkg/billing/stripe.go b/app/pkg/billing/stripe.go
index 921b1c72d..9a0e2a1d7 100644
--- a/app/pkg/billing/stripe.go
+++ b/app/pkg/billing/stripe.go
@@ -129,6 +129,10 @@ func (c *Client) GetPaymentInfo() (*models.PaymentInfo, error) {
AddressPostalCode: card.AddressZip,
}
+ if customer.TaxInfo != nil {
+ info.VATNumber = customer.TaxInfo.TaxID
+ }
+
return info, nil
}
@@ -143,6 +147,10 @@ func (c *Client) ClearPaymentInfo() error {
customerID := c.tenant.Billing.StripeCustomerID
_, err = c.stripe.Customers.Update(customerID, &stripe.CustomerParams{
Email: stripe.String(""),
+ TaxInfo: &stripe.CustomerTaxInfoParams{
+ Type: stripe.String(string(stripe.CustomerTaxInfoTypeVAT)),
+ TaxID: stripe.String(""),
+ },
})
if err != nil {
return errors.Wrap(err, "failed to delete customer billing email")
@@ -168,15 +176,29 @@ func (c *Client) UpdatePaymentInfo(input *models.CreateEditBillingPaymentInfo) e
return err
}
- // email is different, update it
- if current == nil || current.Email != input.Email {
- _, err = c.stripe.Customers.Update(customerID, &stripe.CustomerParams{
- Email: stripe.String(input.Email),
- Description: stripe.String(customerDesc(c.tenant)),
- })
- if err != nil {
- return errors.Wrap(err, "failed to update customer billing email")
- }
+ // update customer info
+ params := &stripe.CustomerParams{
+ Email: stripe.String(input.Email),
+ Shipping: &stripe.CustomerShippingDetailsParams{
+ Name: stripe.String(input.Name),
+ Address: &stripe.AddressParams{
+ City: stripe.String(input.AddressCity),
+ Country: stripe.String(input.AddressCountry),
+ Line1: stripe.String(input.AddressLine1),
+ Line2: stripe.String(input.AddressLine2),
+ PostalCode: stripe.String(input.AddressPostalCode),
+ State: stripe.String(input.AddressState),
+ },
+ },
+ Description: stripe.String(customerDesc(c.tenant)),
+ TaxInfo: &stripe.CustomerTaxInfoParams{
+ Type: stripe.String(string(stripe.CustomerTaxInfoTypeVAT)),
+ TaxID: stripe.String(input.VATNumber),
+ },
+ }
+ _, err = c.stripe.Customers.Update(customerID, params)
+ if err != nil {
+ return errors.Wrap(err, "failed to update customer billing email")
}
// new card, just create it
@@ -301,9 +323,11 @@ func (c *Client) Subscribe(planID string) error {
},
},
})
+
if err != nil {
return errors.Wrap(err, "failed to update stripe subscription")
}
+
c.tenant.Billing.SubscriptionEndsAt = nil
} else {
sub, err := c.stripe.Subscriptions.New(&stripe.SubscriptionParams{
@@ -314,9 +338,11 @@ func (c *Client) Subscribe(planID string) error {
},
},
})
+
if err != nil {
return errors.Wrap(err, "failed to create stripe subscription")
}
+
c.tenant.Billing.StripeSubscriptionID = sub.ID
}
@@ -336,3 +362,20 @@ func (c *Client) CancelSubscription() error {
c.tenant.Billing.SubscriptionEndsAt = &endDate
return nil
}
+
+// GetUpcomingInvoice returns the next due invoice for current tenant
+func (c *Client) GetUpcomingInvoice() (*models.UpcomingInvoice, error) {
+ inv, err := c.stripe.Invoices.GetNext(&stripe.InvoiceParams{
+ Customer: stripe.String(c.tenant.Billing.StripeCustomerID),
+ Subscription: stripe.String(c.tenant.Billing.StripeSubscriptionID),
+ })
+ if err != nil {
+ return nil, errors.Wrap(err, "failed to get upcoming invoice")
+ }
+
+ dueDate := time.Unix(inv.Date, 0)
+ return &models.UpcomingInvoice{
+ AmountDue: inv.AmountDue,
+ DueDate: dueDate,
+ }, nil
+}
diff --git a/app/pkg/billing/stripe_test.go b/app/pkg/billing/stripe_test.go
index 99f5f4a63..5a0e17a14 100644
--- a/app/pkg/billing/stripe_test.go
+++ b/app/pkg/billing/stripe_test.go
@@ -11,7 +11,7 @@ import (
. "github.com/getfider/fider/app/pkg/assert"
)
-func TestCreateCustomer(t *testing.T) {
+func TestCreateCustomer_WithSubscription(t *testing.T) {
RegisterT(t)
if !env.IsBillingEnabled() {
return
@@ -30,6 +30,27 @@ func TestCreateCustomer(t *testing.T) {
Expect(customerID).IsNotEmpty()
Expect(customerID).Equals(tenant.Billing.StripeCustomerID)
+ err = client.UpdatePaymentInfo(&models.CreateEditBillingPaymentInfo{
+ Email: "[email protected]",
+ Card: &models.CreateEditBillingPaymentInfoCard{
+ Token: "tok_visa",
+ },
+ })
+ Expect(err).IsNil()
+
+ err = client.Subscribe("plan_EIE1LpQIzPXxOn")
+ Expect(err).IsNil()
+ Expect(tenant.Billing.StripeSubscriptionID).IsNotEmpty()
+ Expect(tenant.Billing.StripePlanID).Equals("plan_EIE1LpQIzPXxOn")
+
+ inv, err := client.GetUpcomingInvoice()
+ Expect(err).IsNil()
+ Expect(int(inv.AmountDue)).Equals(900)
+
+ err = client.CancelSubscription()
+ Expect(err).IsNil()
+ Expect(tenant.Billing.SubscriptionEndsAt).IsNotNil()
+
err = client.DeleteCustomer()
Expect(err).IsNil()
}
@@ -59,7 +80,8 @@ func TestUpdatePaymentInfo(t *testing.T) {
//Creating a new card
err = client.UpdatePaymentInfo(&models.CreateEditBillingPaymentInfo{
- Email: "[email protected]",
+ Email: "[email protected]",
+ VATNumber: "IE1234",
Card: &models.CreateEditBillingPaymentInfoCard{
Token: "tok_visa",
},
@@ -72,6 +94,7 @@ func TestUpdatePaymentInfo(t *testing.T) {
Expect(info.StripeCardID).IsNotEmpty()
Expect(info.Email).Equals("[email protected]")
+ Expect(info.VATNumber).Equals("IE1234")
Expect(info.CardBrand).Equals("Visa")
Expect(info.CardCountry).Equals("US")
Expect(info.CardLast4).Equals("4242")
@@ -101,6 +124,7 @@ func TestUpdatePaymentInfo(t *testing.T) {
info, err = client.GetPaymentInfo()
Expect(err).IsNil()
Expect(info.Name).Equals("Jon Snow")
+ Expect(info.VATNumber).Equals("")
Expect(info.CardLast4).Equals("4242")
Expect(info.AddressLine1).Equals("Street 1")
Expect(info.AddressLine2).Equals("Av. ABC")
@@ -123,6 +147,7 @@ func TestUpdatePaymentInfo(t *testing.T) {
Expect(info.StripeCardID).IsNotEmpty()
Expect(info.StripeCardID).NotEquals(firstCardID)
Expect(info.Email).Equals("[email protected]")
+ Expect(info.VATNumber).Equals("")
Expect(info.CardBrand).Equals("Visa")
Expect(info.CardCountry).Equals("BR")
Expect(info.CardLast4).Equals("0002")
@@ -148,7 +173,7 @@ func TestListPlans(t *testing.T) {
Expect(err).IsNil()
Expect(plans).HasLen(3)
Expect(plans[0].ID).Equals("plan_EIE1LpQIzPXxOn")
- Expect(plans[0].Name).Equals("Fider Starter (monthly)")
+ Expect(plans[0].Name).Equals("Fider Starter")
Expect(plans[1].ID).Equals("plan_DoK187GZcnFpKY")
Expect(plans[1].Name).Equals("Fider Business (monthly)")
Expect(plans[2].ID).Equals("plan_DpN9SkJMjNTvLd")
diff --git a/app/pkg/env/env.go b/app/pkg/env/env.go
index d4c2c454a..961bba278 100644
--- a/app/pkg/env/env.go
+++ b/app/pkg/env/env.go
@@ -129,7 +129,7 @@ func mustBeSet(name string) {
// IsBillingEnabled returns true if billing is enabled
func IsBillingEnabled() bool {
- return Config.Stripe.SecretKey != "" && Config.Stripe.PublicKey != ""
+ return Config.Stripe.SecretKey != ""
}
// IsSingleHostMode returns true if host mode is set to single tenant
diff --git a/app/services.go b/app/services.go
index 134a31861..f768752ae 100644
--- a/app/services.go
+++ b/app/services.go
@@ -5,12 +5,14 @@ import (
"github.com/getfider/fider/app/pkg/billing"
"github.com/getfider/fider/app/pkg/blob"
"github.com/getfider/fider/app/pkg/email"
+ "github.com/getfider/fider/app/pkg/log"
"github.com/getfider/fider/app/pkg/oauth"
"github.com/getfider/fider/app/storage"
)
// Services holds reference to all Fider services
type Services struct {
+ Logger log.Logger
OAuth oauth.Service
Users storage.User
Tags storage.Tag
diff --git a/app/storage/postgres/tenant.go b/app/storage/postgres/tenant.go
index e567cc0d2..6feef6885 100644
--- a/app/storage/postgres/tenant.go
+++ b/app/storage/postgres/tenant.go
@@ -257,8 +257,13 @@ func (s *TenantStorage) UpdateSettings(settings *models.UpdateTenantSettings) er
// UpdateBillingSettings of current tenant
func (s *TenantStorage) UpdateBillingSettings(billing *models.TenantBilling) error {
- query := "UPDATE tenants_billing SET stripe_customer_id = $1, stripe_plan_id = $2, stripe_subscription_id = $3, subscription_ends_at = $4 WHERE tenant_id = $5"
- _, err := s.trx.Execute(query, billing.StripeCustomerID, billing.StripePlanID, billing.StripeSubscriptionID, billing.SubscriptionEndsAt, s.current.ID)
+ _, err := s.trx.Execute(`
+ UPDATE tenants_billing
+ SET stripe_customer_id = $1, stripe_plan_id = $2, stripe_subscription_id = $3,
+ subscription_ends_at = $4
+ WHERE tenant_id = $5
+ `, billing.StripeCustomerID, billing.StripePlanID, billing.StripeSubscriptionID,
+ billing.SubscriptionEndsAt, s.current.ID)
if err != nil {
return errors.Wrap(err, "failed update tenant billing settings")
}
diff --git a/app/storage/postgres/tenant_test.go b/app/storage/postgres/tenant_test.go
index 418655711..ca842ea2f 100644
--- a/app/storage/postgres/tenant_test.go
+++ b/app/storage/postgres/tenant_test.go
@@ -16,6 +16,7 @@ func TestTenantStorage_Add_Activate(t *testing.T) {
SetupDatabaseTest(t)
defer TeardownDatabaseTest()
+ env.Config.Stripe.SecretKey = ""
tenant, err := tenants.Add("My Domain Inc.", "mydomain", models.TenantPending)
Expect(err).IsNil()
@@ -45,7 +46,6 @@ func TestTenantStorage_Add_WithBillingEnabled(t *testing.T) {
defer TeardownDatabaseTest()
env.Config.Stripe.SecretKey = "sk_1"
- env.Config.Stripe.PublicKey = "pk_1"
tenant, err := tenants.Add("My Domain Inc.", "mydomain", models.TenantPending)
Expect(err).IsNil()
diff --git a/public/assets/styles/variables.scss b/public/assets/styles/variables.scss
index be77c66ab..3879c227d 100644
--- a/public/assets/styles/variables.scss
+++ b/public/assets/styles/variables.scss
@@ -55,6 +55,28 @@ $green-scale: (
lightest: $green-lightest,
);
+// http://www.colorbox.io
+// Hue 40 to 40 SineEaseOut
+// Saturation 5 to 80 SineEaseOut
+// Luminosity 100 to 40 SineEaseOut
+$yellow-darkest: #664400;
+$yellow-darker: #8D5E00;
+$yellow-dark: #B47800;
+$yellow: #D78F00;
+$yellow-light: #EFAA20;
+$yellow-lighter: #FBD382;
+$yellow-lightest: #FFF7E6;
+
+$yellow-scale: (
+ darkest: $yellow-darkest,
+ darker: $yellow-darker,
+ dark: $yellow-dark,
+ default: $yellow,
+ light: $yellow-light,
+ lighter: $yellow-lighter,
+ lightest: $yellow-lightest,
+);
+
// http://www.colorbox.io
// Hue 0 to 0 SineEaseOut
// Saturation 5 to 80 SineEaseOut
@@ -77,7 +99,6 @@ $red-scale: (
lightest: $red-lightest,
);
-
// http://www.colorbox.io
// Hue 220 to 220 SineEaseOut
// Saturation 5 to 80 SineEaseOut
@@ -90,10 +111,6 @@ $blue-light: #89acf1;
$blue-lighter: #bfd4fc;
$blue-lightest: #f2f7ff;
-$main-color: #3b4ade;
-$admin-color: #3b4ade;
-$link-color: #3664c1;
-
$blue-scale: (
darkest: $blue-darkest,
darker: $blue-darker,
@@ -104,6 +121,10 @@ $blue-scale: (
lightest: $blue-lightest,
);
+$main-color: #3b4ade;
+$admin-color: #3b4ade;
+$link-color: #3664c1;
+
$orange: #ff9320;
// Queries
diff --git a/public/components/common/Message.scss b/public/components/common/Message.scss
index 46cf57ace..042ad87e4 100644
--- a/public/components/common/Message.scss
+++ b/public/components/common/Message.scss
@@ -16,6 +16,12 @@
background-color: $green-lightest;
}
+ &.m-warning {
+ color: $yellow-darker;
+ border-left: 4px solid $yellow;
+ background-color: $yellow-lightest;
+ }
+
&.m-error {
color: $red-darker;
border-left: 4px solid $red;
diff --git a/public/components/common/Message.tsx b/public/components/common/Message.tsx
index a5c0da073..210576b2f 100644
--- a/public/components/common/Message.tsx
+++ b/public/components/common/Message.tsx
@@ -2,10 +2,10 @@ import "./Message.scss";
import React from "react";
import { classSet } from "@fider/services";
-import { FaBan, FaRegCheckCircle } from "react-icons/fa";
+import { FaBan, FaRegCheckCircle, FaExclamationTriangle } from "react-icons/fa";
interface MessageProps {
- type: "success" | "error";
+ type: "success" | "warning" | "error";
showIcon?: boolean;
}
@@ -15,7 +15,8 @@ export const Message: React.StatelessComponent<MessageProps> = props => {
[`m-${props.type}`]: true
});
- const icon = props.type === "error" ? <FaBan /> : <FaRegCheckCircle />;
+ const icon =
+ props.type === "error" ? <FaBan /> : props.type === "warning" ? <FaExclamationTriangle /> : <FaRegCheckCircle />;
return (
<p className={className}>
diff --git a/public/components/common/Modal.tsx b/public/components/common/Modal.tsx
index 257512ee5..d77983a8c 100644
--- a/public/components/common/Modal.tsx
+++ b/public/components/common/Modal.tsx
@@ -56,9 +56,6 @@ class ModalWindow extends React.Component<ModalWindowProps, ModalWindowState> {
if (event.keyCode === 27) {
// ESC
this.close();
- } else if (event.keyCode === 9) {
- // TAB
- event.preventDefault();
}
};
diff --git a/public/components/common/form/Input.tsx b/public/components/common/form/Input.tsx
index 33483b8f4..663b4db78 100644
--- a/public/components/common/form/Input.tsx
+++ b/public/components/common/form/Input.tsx
@@ -8,7 +8,9 @@ interface InputProps {
field: string;
label?: string;
className?: string;
+ autoComplete?: string;
autoFocus?: boolean;
+ noTabFocus?: boolean;
afterLabel?: JSX.Element;
icon?: IconType;
maxLength?: number;
@@ -69,6 +71,8 @@ export const Input: React.StatelessComponent<InputProps> = props => {
<input
id={`input-${props.field}`}
type="text"
+ autoComplete={props.autoComplete}
+ tabIndex={props.noTabFocus ? -1 : undefined}
ref={props.inputRef}
autoFocus={props.autoFocus}
onFocus={props.onFocus}
diff --git a/public/models/billing.ts b/public/models/billing.ts
index b624b3106..fad626289 100644
--- a/public/models/billing.ts
+++ b/public/models/billing.ts
@@ -11,6 +11,12 @@ export interface PaymentInfo {
addressLine2: string;
addressState: string;
addressPostalCode: string;
+ vatNumber: string;
+}
+
+export interface InvoiceDue {
+ amountDue: number;
+ dueDate: string;
}
export interface BillingPlan {
@@ -21,3 +27,9 @@ export interface BillingPlan {
price: number;
interval: "month" | "year";
}
+
+export interface Country {
+ code: string;
+ name: string;
+ isEU: boolean;
+}
diff --git a/public/pages/Administration/components/BillingPlanPanel.scss b/public/pages/Administration/components/BillingPlanPanel.scss
deleted file mode 100644
index e69de29bb..000000000
diff --git a/public/pages/Administration/components/BillingPlanPanel.tsx b/public/pages/Administration/components/BillingPlanPanel.tsx
index afbdaf08c..a3ffad65a 100644
--- a/public/pages/Administration/components/BillingPlanPanel.tsx
+++ b/public/pages/Administration/components/BillingPlanPanel.tsx
@@ -1,9 +1,7 @@
-import "./BillingPlanPanel.scss";
-
import React from "react";
import { Segment, Button, Moment, Modal, ButtonClickEvent } from "@fider/components";
-import { BillingPlan } from "@fider/models";
-import { Fider, actions } from "@fider/services";
+import { BillingPlan, InvoiceDue } from "@fider/models";
+import { Fider, actions, classSet } from "@fider/services";
interface BillingPlanOptionProps {
tenantUserCount: number;
@@ -16,9 +14,12 @@ interface BillingPlanOptionProps {
const BillingPlanOption = (props: BillingPlanOptionProps) => {
const billing = Fider.session.tenant.billing!;
+ const isSelected = billing.stripePlanID === props.plan.id && !billing.subscriptionEndsAt;
+ const className = classSet({ "l-plan": true, selected: isSelected });
+
return (
<div className="col-md-4">
- <Segment className="l-plan">
+ <Segment className={className}>
<p className="l-title">{props.plan.name}</p>
<p className="l-description">{props.plan.description}</p>
<p>
@@ -26,17 +27,16 @@ const BillingPlanOption = (props: BillingPlanOptionProps) => {
<span className="l-price">{props.plan.price / 100}</span>
<span className="l-interval">/{props.plan.interval}</span>
</p>
- {billing.stripePlanID === props.plan.id && !billing.subscriptionEndsAt && (
+ {isSelected && (
<>
<p>
<Button disabled={props.disabled} color="danger" onClick={props.onCancel.bind(undefined, props.plan)}>
Cancel
</Button>
</p>
- <p className="info">You are subscribed to this plan.</p>
</>
)}
- {(billing.stripePlanID !== props.plan.id || !!billing.subscriptionEndsAt) && (
+ {!isSelected && (
<>
<p>
<Button
@@ -48,17 +48,13 @@ const BillingPlanOption = (props: BillingPlanOptionProps) => {
</p>
</>
)}
- {props.plan.maxUsers > 0 && (
- <p className="info">
- You have <strong>{props.tenantUserCount}</strong> tracked users.
- </p>
- )}
</Segment>
</div>
);
};
interface BillingPlanPanelProps {
+ invoiceDue: InvoiceDue;
tenantUserCount: number;
disabled: boolean;
plans: BillingPlan[];
@@ -172,6 +168,27 @@ export class BillingPlanPanel extends React.Component<BillingPlanPanelProps, Bil
<Segment className="l-billing-plans">
<h4>Plans</h4>
+ {currentPlan && (
+ <p className="info">
+ {billing.subscriptionEndsAt ? (
+ <>
+ Your <strong>{currentPlan.name}</strong> subscription ends at{" "}
+ <strong>
+ <Moment date={billing.subscriptionEndsAt} format="full" />
+ </strong>
+ . Subscribe to a new plan and avoid a service interruption.
+ </>
+ ) : (
+ <>
+ Your upcoming invoice of <strong>${this.props.invoiceDue.amountDue / 100}</strong> is due on{" "}
+ <strong>
+ <Moment date={this.props.invoiceDue.dueDate} format="full" />
+ </strong>
+ .
+ </>
+ )}
+ </p>
+ )}
{!billing.stripePlanID && (
<p className="info">
You don't have any active subscription.
@@ -186,15 +203,6 @@ export class BillingPlanPanel extends React.Component<BillingPlanPanelProps, Bil
)}
</p>
)}
- {currentPlan && !!billing.subscriptionEndsAt && (
- <p className="info">
- Your <strong>{currentPlan.name}</strong> ends at{" "}
- <strong>
- <Moment date={billing.subscriptionEndsAt} format="full" />
- </strong>
- . Subscribe to a new plan and avoid a service interruption.
- </p>
- )}
<div className="row">
{this.props.plans.map(x => (
<BillingPlanOption
@@ -208,6 +216,13 @@ export class BillingPlanPanel extends React.Component<BillingPlanPanelProps, Bil
/>
))}
</div>
+ <div className="row">
+ <div className="col-md-12">
+ <p className="info">
+ You have <strong>{this.props.tenantUserCount}</strong> tracked users.
+ </p>
+ </div>
+ </div>
</Segment>
</>
);
diff --git a/public/pages/Administration/components/PaymentInfoModal.tsx b/public/pages/Administration/components/PaymentInfoModal.tsx
index d828df7f1..e38499d4c 100644
--- a/public/pages/Administration/components/PaymentInfoModal.tsx
+++ b/public/pages/Administration/components/PaymentInfoModal.tsx
@@ -2,7 +2,7 @@ import React from "react";
import { injectStripe, CardElement } from "react-stripe-elements";
import { Input, Field, Button, Form, Select, SelectOption, Modal, CardInfo } from "@fider/components";
import { Failure, actions } from "@fider/services";
-import { PaymentInfo } from "@fider/models";
+import { PaymentInfo, Country } from "@fider/models";
type PatchedTokenResponse = stripe.TokenResponse & {
error?: { decline_code?: string };
@@ -17,7 +17,7 @@ interface StripeProps {
interface PaymentInfoModalProps {
paymentInfo?: PaymentInfo;
stripe?: StripeProps;
- countries: Array<{ code: string; name: string }>;
+ countries: Country[];
onClose: () => void;
}
@@ -31,6 +31,7 @@ interface PaymentInfoModalState {
addressState: string;
addressPostalCode: string;
addressCountry: string;
+ vatNumber: string;
stripe: stripe.Stripe | null;
error?: Failure;
}
@@ -48,7 +49,8 @@ class PaymentInfoModal extends React.Component<PaymentInfoModalProps, PaymentInf
addressCity: this.props.paymentInfo ? this.props.paymentInfo.addressCity : "",
addressState: this.props.paymentInfo ? this.props.paymentInfo.addressState : "",
addressPostalCode: this.props.paymentInfo ? this.props.paymentInfo.addressPostalCode : "",
- addressCountry: this.props.paymentInfo ? this.props.paymentInfo.addressCountry : ""
+ addressCountry: this.props.paymentInfo ? this.props.paymentInfo.addressCountry : "",
+ vatNumber: this.props.paymentInfo ? this.props.paymentInfo.vatNumber : ""
};
}
@@ -140,6 +142,10 @@ class PaymentInfoModal extends React.Component<PaymentInfoModalProps, PaymentInf
this.setState({ addressPostalCode });
};
+ private setVATNumber = (vatNumber: string) => {
+ this.setState({ vatNumber });
+ };
+
private setAddressCountry = (option: SelectOption | undefined) => {
if (option) {
this.setState({ addressCountry: option.value });
@@ -154,6 +160,16 @@ class PaymentInfoModal extends React.Component<PaymentInfoModalProps, PaymentInf
this.setState({ changingCard: true });
};
+ private isEUCountry(): boolean {
+ if (this.state.addressCountry) {
+ const filtered = this.props.countries.filter(x => x.code === this.state.addressCountry);
+ if (filtered && filtered.length > 0) {
+ return filtered[0].isEU;
+ }
+ }
+ return false;
+ }
+
public render() {
return (
<Modal.Window isOpen={true} center={false} size="large" onClose={this.props.onClose}>
@@ -162,7 +178,7 @@ class PaymentInfoModal extends React.Component<PaymentInfoModalProps, PaymentInf
<div className="row">
{(!this.props.paymentInfo || this.state.changingCard) && (
<div className="col-md-12">
- <Field label="Card" field="card">
+ <Field label="Credit/Debit Card" field="card">
<CardElement />
<p className="info">
We neither store or see your card information. We integrate directly with Stripe.
@@ -173,7 +189,7 @@ class PaymentInfoModal extends React.Component<PaymentInfoModalProps, PaymentInf
{this.props.paymentInfo && !this.state.changingCard && (
<div className="col-md-12">
<Field
- label="Card"
+ label="Credit/Debit Card"
field="card"
afterLabel={
<span className="ui info clickable" onClick={this.changeCard}>
@@ -191,10 +207,16 @@ class PaymentInfoModal extends React.Component<PaymentInfoModalProps, PaymentInf
</div>
)}
<div className="col-md-12">
- <Input label="Name" field="name" value={this.state.name} onChange={this.setName} />
+ <Input label="Name" field="name" value={this.state.name} onChange={this.setName} autoComplete="name" />
</div>
<div className="col-md-12">
- <Input label="Email" field="email" value={this.state.email} onChange={this.setEmail} />
+ <Input
+ label="Email"
+ field="email"
+ value={this.state.email}
+ onChange={this.setEmail}
+ autoComplete="email"
+ />
</div>
<div className="col-md-6">
<Input
@@ -202,6 +224,7 @@ class PaymentInfoModal extends React.Component<PaymentInfoModalProps, PaymentInf
value={this.state.addressLine1}
field="addressLine1"
onChange={this.setAddressLine1}
+ autoComplete="address-line1"
/>
</div>
<div className="col-md-6">
@@ -210,28 +233,37 @@ class PaymentInfoModal extends React.Component<PaymentInfoModalProps, PaymentInf
value={this.state.addressLine2}
field="addressLine2"
onChange={this.setAddressLine2}
+ autoComplete="address-line2"
/>
</div>
- <div className="col-md-3">
- <Input label="City" field="addressCity" value={this.state.addressCity} onChange={this.setAddressCity} />
+ <div className="col-md-4">
+ <Input
+ label="City"
+ field="addressCity"
+ value={this.state.addressCity}
+ onChange={this.setAddressCity}
+ autoComplete="address-level2"
+ />
</div>
- <div className="col-md-3">
+ <div className="col-md-4">
<Input
label="State / Region"
field="addressState"
value={this.state.addressState}
onChange={this.setAddressState}
+ autoComplete="address-level1"
/>
</div>
- <div className="col-md-3">
+ <div className="col-md-4">
<Input
label="Postal Code"
field="addressPostalCode"
value={this.state.addressPostalCode}
onChange={this.setAddressPostalCode}
+ autoComplete="postal-code"
/>
</div>
- <div className="col-md-3">
+ <div className="col-md-6">
<Select
label="Country"
field="addressCountry"
@@ -243,6 +275,16 @@ class PaymentInfoModal extends React.Component<PaymentInfoModalProps, PaymentInf
]}
/>
</div>
+ {this.isEUCountry() && (
+ <div className="col-md-6">
+ <Input
+ label="VAT Number"
+ field="vatNumber"
+ value={this.state.vatNumber}
+ onChange={this.setVATNumber}
+ />
+ </div>
+ )}
</div>
</Form>
</Modal.Content>
diff --git a/public/pages/Administration/pages/Billing.page.scss b/public/pages/Administration/pages/Billing.page.scss
index d61cf8214..63317485a 100644
--- a/public/pages/Administration/pages/Billing.page.scss
+++ b/public/pages/Administration/pages/Billing.page.scss
@@ -3,25 +3,35 @@
#p-admin-billing {
.l-plan {
padding: 10px;
+ border: 1px solid transparent;
+
+ &.selected {
+ border: 1px solid $main-color;
+ }
+
.l-title {
color: $main-color;
font-size: $font-size-large;
font-weight: 600;
}
- }
- .l-description {
- min-height: 40px;
- }
- span.l-dollar {
- color: $gray-darker;
- font-size: $font-size-small;
- vertical-align: top;
- }
- span.l-price {
- font-size: $font-size-big;
- }
- span.l-interval {
- color: $gray-darker;
- font-size: $font-size-small;
+
+ .l-description {
+ min-height: 40px;
+ }
+
+ span.l-dollar {
+ color: $gray-darker;
+ font-size: $font-size-small;
+ vertical-align: top;
+ }
+
+ span.l-price {
+ font-size: $font-size-big;
+ }
+
+ span.l-interval {
+ color: $gray-darker;
+ font-size: $font-size-small;
+ }
}
}
\ No newline at end of file
diff --git a/public/pages/Administration/pages/Billing.page.tsx b/public/pages/Administration/pages/Billing.page.tsx
index da2648fa2..9e8d1378e 100644
--- a/public/pages/Administration/pages/Billing.page.tsx
+++ b/public/pages/Administration/pages/Billing.page.tsx
@@ -4,18 +4,19 @@ import React from "react";
import { FaFileInvoice } from "react-icons/fa";
import { AdminBasePage } from "../components/AdminBasePage";
-import { Segment, Button, CardInfo } from "@fider/components";
-import { PaymentInfo, BillingPlan } from "@fider/models";
+import { Segment, Button, CardInfo, Message } from "@fider/components";
+import { PaymentInfo, BillingPlan, Country, InvoiceDue } from "@fider/models";
import { Fider } from "@fider/services";
import PaymentInfoModal from "../components/PaymentInfoModal";
import { StripeProvider, Elements } from "react-stripe-elements";
import { BillingPlanPanel } from "../components/BillingPlanPanel";
interface BillingPageProps {
+ invoiceDue: InvoiceDue;
plans: BillingPlan[];
tenantUserCount: number;
paymentInfo?: PaymentInfo;
- countries: Array<{ code: string; name: string }>;
+ countries: Country[];
}
interface BillingPageState {
@@ -93,7 +94,7 @@ export default class BillingPage extends AdminBasePage<BillingPageProps, Billing
)}
{!this.props.paymentInfo && (
<>
- <p>You don't have any payment method set up. Start by adding one.</p>
+ <Message type="warning">You don't have any payment method set up. Start by adding one.</Message>
<Button onClick={this.openModal}>Add</Button>
</>
)}
@@ -101,6 +102,7 @@ export default class BillingPage extends AdminBasePage<BillingPageProps, Billing
</div>
<div className="col-md-12">
<BillingPlanPanel
+ invoiceDue={this.props.invoiceDue}
tenantUserCount={this.props.tenantUserCount}
disabled={!this.props.paymentInfo}
plans={this.props.plans}
diff --git a/public/pages/Administration/pages/GeneralSettings.page.tsx b/public/pages/Administration/pages/GeneralSettings.page.tsx
index e8ff20930..3e069cb1d 100644
--- a/public/pages/Administration/pages/GeneralSettings.page.tsx
+++ b/public/pages/Administration/pages/GeneralSettings.page.tsx
@@ -89,22 +89,40 @@ export default class GeneralSettingsPage extends AdminBasePage<{}, GeneralSettin
value={this.state.title}
disabled={!Fider.session.user.isAdministrator}
onChange={this.setTitle}
- />
+ >
+ <p className="info">
+ The title is used on the header, emails, notifications and SEO content. Keep it short and simple. The
+ product/service name is usually the best choice.
+ </p>
+ </Input>
+
<TextArea
field="welcomeMessage"
label="Welcome Message"
value={this.state.welcomeMessage}
disabled={!Fider.session.user.isAdministrator}
onChange={this.setWelcomeMessage}
- />
+ >
+ <p className="info">
+ The message is shown on this site's home page. Use it to help visitors understad what this space is about
+ and the importance of their feedback. Leave it empty for a default message.
+ </p>
+ </TextArea>
+
<Input
field="invitation"
label="Invitation"
maxLength={60}
value={this.state.invitation}
disabled={!Fider.session.user.isAdministrator}
+ placeholder="Enter your suggestion here..."
onChange={this.setInvitation}
- />
+ >
+ <p className="info">
+ This text is used as a placeholder for the suggestion's text box. Use it to invite your visitors into
+ sharing their suggestions and feedback. Leave it empty for a default message.
+ </p>
+ </Input>
<ImageUploader
label="Logo"
diff --git a/public/pages/Home/components/PostInput.tsx b/public/pages/Home/components/PostInput.tsx
index b9636ac35..71a37c322 100644
--- a/public/pages/Home/components/PostInput.tsx
+++ b/public/pages/Home/components/PostInput.tsx
@@ -94,6 +94,7 @@ export class PostInput extends React.Component<PostInputProps, PostInputState> {
<Form error={this.state.error}>
<Input
field="title"
+ noTabFocus={!Fider.session.isAuthenticated}
inputRef={this.setInputRef}
onFocus={this.handleTitleFocus}
maxLength={100}
diff --git a/public/pages/Home/components/PostsContainer.tsx b/public/pages/Home/components/PostsContainer.tsx
index 6ddfb8c50..d4d3e616d 100644
--- a/public/pages/Home/components/PostsContainer.tsx
+++ b/public/pages/Home/components/PostsContainer.tsx
@@ -67,7 +67,7 @@ export class PostsContainer extends React.Component<PostsContainerProps, PostsCo
this.setState({ loading: false, posts: response.data });
}
});
- }, 200);
+ }, 500);
}
private handleViewChanged = (view: string) => {
diff --git a/public/pages/Home/components/SimilarPosts.tsx b/public/pages/Home/components/SimilarPosts.tsx
index 6bc4f7588..6223da03d 100644
--- a/public/pages/Home/components/SimilarPosts.tsx
+++ b/public/pages/Home/components/SimilarPosts.tsx
@@ -43,7 +43,7 @@ export class SimilarPosts extends React.Component<SimilarPostsProps, SimilarPost
private timer?: number;
public componentDidUpdate() {
window.clearTimeout(this.timer);
- this.timer = window.setTimeout(this.loadSimilarPosts, 200);
+ this.timer = window.setTimeout(this.loadSimilarPosts, 500);
}
private loadSimilarPosts = () => {
diff --git a/public/pages/ShowPost/components/PostSearch.tsx b/public/pages/ShowPost/components/PostSearch.tsx
index 9fe402472..c92dbce10 100644
--- a/public/pages/ShowPost/components/PostSearch.tsx
+++ b/public/pages/ShowPost/components/PostSearch.tsx
@@ -44,7 +44,7 @@ export class PostSearch extends React.Component<PostSearchProps, PostSearchState
this.setState({ posts });
}
});
- }, 200);
+ }, 500);
};
public render() {
diff --git a/public/pages/SignUp/SignUp.page.tsx b/public/pages/SignUp/SignUp.page.tsx
index 4051175a7..0495cdedc 100644
--- a/public/pages/SignUp/SignUp.page.tsx
+++ b/public/pages/SignUp/SignUp.page.tsx
@@ -92,7 +92,7 @@ export default class SignUpPage extends React.Component<{}, SignUpPageState> {
}
});
});
- }, 200);
+ }, 500);
};
private setSubdomain = async (subdomain: string) => {
diff --git a/public/pages/UI/UIToolkit.page.scss b/public/pages/UI/UIToolkit.page.scss
index 1ef32388c..73747b0a9 100644
--- a/public/pages/UI/UIToolkit.page.scss
+++ b/public/pages/UI/UIToolkit.page.scss
@@ -42,6 +42,17 @@ $color-box-size: 100px;
}
}
+ @each $name, $color in $yellow-scale {
+ &.yellow-#{$name} {
+ color: textColorFor($color);
+ box-shadow: 0px 1px 1px 0px rgba(textColorFor($color), 0.2);
+ background-color: $color;
+ &:before {
+ content: "#{$color}";
+ }
+ }
+ }
+
@each $name, $color in $red-scale {
&.red-#{$name} {
color: textColorFor($color);
diff --git a/public/pages/UI/UIToolkit.page.tsx b/public/pages/UI/UIToolkit.page.tsx
index d4c78b95e..62363df8d 100644
--- a/public/pages/UI/UIToolkit.page.tsx
+++ b/public/pages/UI/UIToolkit.page.tsx
@@ -148,6 +148,15 @@ export default class UIToolkitPage extends React.Component<{}, UIToolkitPageStat
<div className="color blue-lighter" />
<div className="color blue-lightest" />
</div>
+ <div className="color-scale">
+ <div className="color yellow-darkest" />
+ <div className="color yellow-darker" />
+ <div className="color yellow-dark" />
+ <div className="color yellow-default" />
+ <div className="color yellow-light" />
+ <div className="color yellow-lighter" />
+ <div className="color yellow-lightest" />
+ </div>
<h1>Heading 1</h1>
<h2>Heading 2</h2>
diff --git a/public/services/actions/billing.ts b/public/services/actions/billing.ts
index 88430a978..3f80ac554 100644
--- a/public/services/actions/billing.ts
+++ b/public/services/actions/billing.ts
@@ -13,6 +13,7 @@ interface UpdatePaymentInfoRequest {
addressState: string;
addressPostalCode: string;
addressCountry: string;
+ vatNumber: string;
}
export const updatePaymentInfo = async (request: UpdatePaymentInfoRequest): Promise<Result> => {
diff --git a/vendor/github.com/goenning/vat/LICENSE b/vendor/github.com/goenning/vat/LICENSE
new file mode 100644
index 000000000..b09711e93
--- /dev/null
+++ b/vendor/github.com/goenning/vat/LICENSE
@@ -0,0 +1,21 @@
+MIT License
+
+Copyright (c) 2019 Guilherme Oenning
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
\ No newline at end of file
diff --git a/vendor/github.com/goenning/vat/Makefile b/vendor/github.com/goenning/vat/Makefile
new file mode 100644
index 000000000..21905e9b9
--- /dev/null
+++ b/vendor/github.com/goenning/vat/Makefile
@@ -0,0 +1,5 @@
+test:
+ GOCACHE=off go test -v -timeout 1m .
+
+
+.PHONY: test
diff --git a/vendor/github.com/goenning/vat/README.md b/vendor/github.com/goenning/vat/README.md
new file mode 100644
index 000000000..89516bcaa
--- /dev/null
+++ b/vendor/github.com/goenning/vat/README.md
@@ -0,0 +1,43 @@
+# Golang VAT number validation
+
+Uses the official [VIES VAT number validation SOAP web service](http://ec.europa.eu/taxation_customs/vies/vatRequest.html?locale=en)
+to validate european VAT numbers.
+
+Unfortunately their service is super unreliable.
+
+## Install
+
+```
+go get -u github.com/goenning/vat
+```
+
+
+## Usage with Go
+
+```go
+import "github.com/goenning/vat"
+
+response, err := vat.Query("IE6388047V")
+if err != nil {
+ // do sth with err
+}
+if response.IsValid {
+ fmt.Println(response.Name)
+}
+```
+
+## Retry
+
+Because VIES service is very unreliable, this package will retry every failed request for a maximum of 4 times using an exponential backoff strategy.
+
+## Greece and United Kingdom
+
+This package always assume that country code is on ISO 3166 list.
+
+Greece's ISO 3166 country code is `GR`, but EU uses `EL`. This package does the conversion so that you don't need to care about EU's country code. Same applies to `UK`, both ISO and EU uses `GB`, but this package will always convert `UK` to `GB` for safety reasons.
+
+This conversion only happens for the CountryCode field and not VAT Number. So a EL094160738 is a **valid** VAT number for the `GR` country.
+
+## Fork
+
+This package is a merge of [mattes/vat](https://github.com/mattes/vat) and [dannyvankooten/vat](https://github.com/dannyvankooten/vat), with some refactoring and other features. Thanks!
\ No newline at end of file
diff --git a/vendor/github.com/goenning/vat/country.go b/vendor/github.com/goenning/vat/country.go
new file mode 100644
index 000000000..122bc4b21
--- /dev/null
+++ b/vendor/github.com/goenning/vat/country.go
@@ -0,0 +1,33 @@
+package vat
+
+import "strings"
+
+//IsEU returns true if given country code is within EU
+func IsEU(countryCode string) bool {
+ if countryCode == "UK" || countryCode == "EL" {
+ return false
+ }
+
+ countryCode = fromISOCountryCode(countryCode)
+ _, ok := vatFormatNumberPatterns[countryCode]
+ return ok
+}
+
+func toISOCountryCode(countryCode string) string {
+ countryCode = strings.TrimSpace(countryCode)
+ if countryCode == "UK" {
+ return "GB"
+ }
+ if countryCode == "EL" {
+ return "GR"
+ }
+ return countryCode
+}
+
+func fromISOCountryCode(countryCode string) string {
+ countryCode = strings.TrimSpace(countryCode)
+ if countryCode == "GR" {
+ return "EL"
+ }
+ return countryCode
+}
diff --git a/vendor/github.com/goenning/vat/format.go b/vendor/github.com/goenning/vat/format.go
new file mode 100644
index 000000000..15b03785a
--- /dev/null
+++ b/vendor/github.com/goenning/vat/format.go
@@ -0,0 +1,72 @@
+package vat
+
+import (
+ "fmt"
+ "regexp"
+ "strings"
+)
+
+var vatFormatNumberPatterns = map[string]string{
+ "AT": `U[A-Z0-9]{8}`,
+ "BE": `(0[0-9]{9}|[0-9]{10})`,
+ "BG": `[0-9]{9,10}`,
+ "CY": `[0-9]{8}[A-Z]`,
+ "CZ": `[0-9]{8,10}`,
+ "DE": `[0-9]{9}`,
+ "DK": `[0-9]{8}`,
+ "EE": `[0-9]{9}`,
+ "EL": `[0-9]{9}`,
+ "ES": `[A-Z][0-9]{7}[A-Z]|[0-9]{8}[A-Z]|[A-Z][0-9]{8}`,
+ "FI": `[0-9]{8}`,
+ "FR": `([A-Z]{2}|[0-9]{2})[0-9]{9}`,
+ "GB": `[0-9]{9}|[0-9]{12}|(GD|HA)[0-9]{3}`,
+ "HR": `[0-9]{11}`,
+ "HU": `[0-9]{8}`,
+ "IE": `[A-Z0-9]{7}[A-Z]|[A-Z0-9]{7}[A-W][A-I]`,
+ "IT": `[0-9]{11}`,
+ "LT": `([0-9]{9}|[0-9]{12})`,
+ "LU": `[0-9]{8}`,
+ "LV": `[0-9]{11}`,
+ "MT": `[0-9]{8}`,
+ "NL": `[0-9]{9}B[0-9]{2}`,
+ "PL": `[0-9]{10}`,
+ "PT": `[0-9]{9}`,
+ "RO": `[0-9]{2,10}`,
+ "SE": `[0-9]{12}`,
+ "SI": `[0-9]{8}`,
+ "SK": `[0-9]{10}`,
+}
+
+// ValidateNumberFormat returns true if given
+func ValidateNumberFormat(vatNumber string) (bool, string) {
+ vatNumber = sanitizeVATNumber(vatNumber)
+
+ if len(vatNumber) < 3 {
+ return false, ""
+ }
+
+ vatNumber = strings.ToUpper(vatNumber)
+ euCoutryCode := vatNumber[0:2]
+ pattern, ok := vatFormatNumberPatterns[euCoutryCode]
+ if !ok {
+ return false, ""
+ }
+
+ matched, err := regexp.MatchString(pattern, vatNumber[2:])
+ if err != nil {
+ panic(fmt.Sprintf("Failed to compile expression '%s'.", pattern))
+ }
+ return matched, toISOCountryCode(euCoutryCode)
+}
+
+func formatAddress(address string) string {
+ address = strings.TrimSpace(address)
+ address = strings.Replace(address, "\n\n", ", ", -1)
+ address = strings.Replace(address, "\n", ", ", -1)
+ return address
+}
+
+func sanitizeVATNumber(vatNumber string) string {
+ vatNumber = strings.TrimSpace(vatNumber)
+ return regexp.MustCompile(" ").ReplaceAllString(vatNumber, "")
+}
diff --git a/vendor/github.com/goenning/vat/go.mod b/vendor/github.com/goenning/vat/go.mod
new file mode 100644
index 000000000..5f440dec9
--- /dev/null
+++ b/vendor/github.com/goenning/vat/go.mod
@@ -0,0 +1 @@
+module github.com/goenning/vat
diff --git a/vendor/github.com/goenning/vat/vat.go b/vendor/github.com/goenning/vat/vat.go
new file mode 100644
index 000000000..a065588c2
--- /dev/null
+++ b/vendor/github.com/goenning/vat/vat.go
@@ -0,0 +1,58 @@
+package vat
+
+import (
+ "errors"
+ "time"
+)
+
+var (
+ // ErrInvalidVATNumberFormat is returned when given VAT Number is in a invalid format
+ ErrInvalidVATNumberFormat = errors.New("vat: invalid VAT number format")
+ // ErrServiceUnreachable is returned when we cannot connect to VIES VAT Service
+ ErrServiceUnreachable = errors.New("vat: VIES service is unreachable")
+ // ErrVIESInvalidInput is returned based on VIES response
+ ErrVIESInvalidInput = errors.New("vat: VAT number is invalid")
+ // ErrVIESGlobalMaxConcurrentRequest is returned based on VIES response
+ ErrVIESGlobalMaxConcurrentRequest = errors.New("vat: the maximum number of global concurrent requests has been reached, try again later")
+ // ErrVIESMSMaxConcurrentRequest is returned based on VIES response
+ ErrVIESMSMaxConcurrentRequest = errors.New("vat: the maximum number of concurrent requests for this member state has been reached, try again later")
+ // ErrVIESServiceUnavailable is returned based on VIES response
+ ErrVIESServiceUnavailable = errors.New("vat: an error was encountered either at the network level or the web application level, try again later")
+ // ErrVIESMSUnavailable is returned based on VIES response
+ ErrVIESMSUnavailable = errors.New("vat: the application at the member state is not replying or not available, try again later")
+ // ErrVIESTimeout is returned based on VIES response
+ ErrVIESTimeout = errors.New("vat: the application did not receive a reply within the allocated time period, try again later")
+)
+
+// Response is the model returned from VIES query
+type Response struct {
+ IsValid bool
+ VATNumber string
+ CountryCode string
+ RequestDate time.Time
+ Name string
+ Address string
+}
+
+// Query VIES service to check if VAT is valid
+func Query(vatNumber string) (*Response, error) {
+ vatNumber = sanitizeVATNumber(vatNumber)
+
+ isValidFormat, _ := ValidateNumberFormat(vatNumber)
+ if !isValidFormat {
+ return nil, ErrInvalidVATNumberFormat
+ }
+
+ var (
+ response *Response
+ err error
+ )
+
+ retry(4, 1*time.Second, func() bool {
+ response, err = sendRequestVIES(vatNumber)
+ // only retry if there's an error and it's different than INVALID_INPUT
+ return err != nil && err != ErrVIESInvalidInput
+ })
+
+ return response, err
+}
diff --git a/vendor/github.com/goenning/vat/vies.go b/vendor/github.com/goenning/vat/vies.go
new file mode 100644
index 000000000..3fd88b16b
--- /dev/null
+++ b/vendor/github.com/goenning/vat/vies.go
@@ -0,0 +1,132 @@
+package vat
+
+import (
+ "bytes"
+ "encoding/xml"
+ "io/ioutil"
+ "math/rand"
+ "net/http"
+ "strings"
+ "text/template"
+ "time"
+)
+
+const serviceURL = "http://ec.europa.eu/taxation_customs/vies/services/checkVatService"
+
+//DefaultClient is the HTTP Client used to communicate with VIES
+var DefaultClient = &http.Client{
+ Timeout: 10 * time.Second,
+ Transport: &http.Transport{
+ DisableKeepAlives: true,
+ },
+}
+
+var envelope *template.Template
+
+var rd struct {
+ XMLName xml.Name `xml:"Envelope"`
+ Soap struct {
+ XMLName xml.Name `xml:"Body"`
+ Soap struct {
+ XMLName xml.Name `xml:"checkVatResponse"`
+ CountryCode string `xml:"countryCode"`
+ VATNumber string `xml:"vatNumber"`
+ Valid bool `xml:"valid"`
+ Name string `xml:"name"`
+ Address string `xml:"address"`
+ }
+ SoapFault struct {
+ XMLName string `xml:"Fault"`
+ Code string `xml:"faultcode"`
+ Message string `xml:"faultstring"`
+ }
+ }
+}
+
+func init() {
+ rand.Seed(time.Now().UnixNano())
+
+ t, err := template.New("envelope").Parse(`
+ <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:v1="http://schemas.conversesolutions.com/xsd/dmticta/v1">
+ <soapenv:Header/>
+ <soapenv:Body>
+ <checkVat xmlns="urn:ec.europa.eu:taxud:vies:services:checkVat:types">
+ <countryCode>{{.countryCode}}</countryCode>
+ <vatNumber>{{.vatNumber}}</vatNumber>
+ </checkVat>
+ </soapenv:Body>
+ </soapenv:Envelope>
+ `)
+ if err != nil {
+ panic("vat: could not parse VIES envelope")
+ }
+ envelope = t
+}
+
+func retry(attempts int, sleep time.Duration, f func() bool) {
+ shouldRetry := f()
+ attempts--
+ if shouldRetry && attempts > 0 {
+ time.Sleep(sleep)
+ retry(attempts, 2*sleep, f)
+ }
+}
+
+func sendRequestVIES(vatNumber string) (*Response, error) {
+ var body bytes.Buffer
+ if err := envelope.Execute(&body, map[string]string{
+ "countryCode": strings.ToUpper(vatNumber[0:2]),
+ "vatNumber": vatNumber[2:],
+ }); err != nil {
+ return nil, err
+ }
+ req, err := http.NewRequest("POST", serviceURL, &body)
+ if err != nil {
+ return nil, err
+ }
+ req.Header.Set("Content-Type", "text/xml;charset=UTF-8")
+ req.Header.Set("Connection", "close")
+
+ res, err := DefaultClient.Do(req)
+ if err != nil {
+ return nil, ErrServiceUnreachable
+ }
+ defer res.Body.Close()
+
+ if res.StatusCode != 200 {
+ return nil, ErrVIESServiceUnavailable
+ }
+
+ xmlResponse, err := ioutil.ReadAll(res.Body)
+ if err != nil {
+ return nil, err
+ }
+
+ if err := xml.Unmarshal(xmlResponse, &rd); err != nil {
+ return nil, err
+ }
+
+ if rd.Soap.SoapFault.Message != "" {
+ if rd.Soap.SoapFault.Message == "INVALID_INPUT" {
+ return nil, ErrVIESInvalidInput
+ } else if rd.Soap.SoapFault.Message == "GLOBAL_MAX_CONCURRENT_REQ" {
+ return nil, ErrVIESGlobalMaxConcurrentRequest
+ } else if rd.Soap.SoapFault.Message == "MS_MAX_CONCURRENT_REQ" {
+ return nil, ErrVIESMSMaxConcurrentRequest
+ } else if rd.Soap.SoapFault.Message == "SERVICE_UNAVAILABLE" {
+ return nil, ErrVIESServiceUnavailable
+ } else if rd.Soap.SoapFault.Message == "MS_UNAVAILABLE" {
+ return nil, ErrVIESMSUnavailable
+ } else if rd.Soap.SoapFault.Message == "TIMEOUT" {
+ return nil, ErrVIESTimeout
+ }
+ }
+
+ return &Response{
+ CountryCode: toISOCountryCode(rd.Soap.Soap.CountryCode),
+ VATNumber: rd.Soap.Soap.VATNumber,
+ IsValid: rd.Soap.Soap.Valid,
+ Name: rd.Soap.Soap.Name,
+ Address: formatAddress(rd.Soap.Soap.Address),
+ }, nil
+}