fixtures

package
v1.35.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 24, 2026 License: MIT Imports: 69 Imported by: 0

Documentation

Index

Constants

View Source
const Month = time.Hour * 24 * 30

Variables

View Source
var BlockchainNamespace = New("blockchain-namespace", func(c *gin.Context) *namespace.Namespace {
	db := datastore.New(c)
	ns := namespace.New(db)
	ns.Id_ = blockchains.BlockchainNamespace
	ns.Name = blockchains.BlockchainNamespace
	ns.IntId = 1234567890

	err := ns.GetOrCreate("Name=", blockchains.BlockchainNamespace)

	if err != nil {
		log.Warn("Failed to put namespace: %v", err)
	}

	ns.Id_ = blockchains.BlockchainNamespace
	ns.Name = blockchains.BlockchainNamespace
	ns.IntId = 1234567890
	ns.MustUpdate()

	return ns
})
View Source
var Campaign = New("campaign", func(c *gin.Context) *campaign.Campaign {
	db := getNamespaceDb(c)
	org := Organization(c)

	campaign := campaign.New(db)
	campaign.Slug = "some-campaign"
	campaign.GetOrCreate("Slug=", campaign.Slug)
	campaign.Parent = org.Key()
	campaign.OrganizationId = org.Id()
	campaign.Approved = true
	campaign.Enabled = true
	campaign.Category = category.Arts
	campaign.Title = "Such shirt!"
	campaign.Description = "Shirt that bring much happiness."

	campaign.MustPut()
	return campaign
})
View Source
var CheckEthereumBalance = New("check-ethereum-balance", func(c *gin.Context) {
	db := datastore.New(c)
	ctx := db.Context

	w := wallet.New(db)
	w.Id_ = "test-customer-wallet"
	w.UseStringKey = true
	w.GetOrCreate("Id_=", "test-customer-wallet")

	if len(w.Accounts) == 0 {
		if _, err := w.CreateAccount("Test Customer Account", blockchains.EthereumRopstenType, []byte(config.Ethereum.TestPassword)); err != nil {
			panic(err)
		}
	}

	pw := wallet.New(db)
	pw.GetOrCreate("Id_=", "platform-wallet")

	account, ok := pw.GetAccountByName("Ethereum Ropsten Test Account")
	if !ok {
		panic(errors.New("Platform Account Not Found."))
	}

	log.Info("Account Found", ctx)
	if err := account.Decrypt([]byte(config.Ethereum.TestPassword)); err != nil {
		panic(err)
	}

	client := ethereum.New(db.Context, config.Ethereum.TestNetNodes[0])

	balance, err := client.GetBalance(account.Address)
	if err != nil {
		panic(err)
	}

	log.Info("Geth Node Response: %v", balance, c)
})
View Source
var Collection = New("collection", func(c *gin.Context) *collection.Collection {
	db := getNamespaceDb(c)

	collection := collection.New(db)
	collection.Slug = "such-tees-pack"
	collection.GetOrCreate("Slug=", collection.Slug)
	collection.Name = "Such tees pack"
	collection.Description = "Much tees in one pack!"
	collection.Published = true
	collection.Available = true

	collection.MustPut()
	return collection
})
View Source
var Coupon = New("coupon", func(c *gin.Context) *coupon.Coupon {
	db := getNamespaceDb(c)

	now := time.Now()

	p := Product(c)

	cpn := coupon.New(db)
	cpn.Code_ = strings.ToUpper("sad-coupon")
	cpn.GetOrCreate("Code=", cpn.Code_)
	cpn.Name = "Sad Coupon"
	cpn.Type = "flat"
	cpn.EndDate = now.Add(Month)
	cpn.Once = true
	cpn.Enabled = true
	cpn.Amount = 500
	cpn.ProductId = p.Id()

	cpn.MustPut()

	cpn = coupon.New(db)
	cpn.Code_ = strings.ToUpper("such-coupon")
	cpn.GetOrCreate("Code=", cpn.Code_)
	cpn.Name = "Such Coupon"
	cpn.Type = "flat"
	cpn.EndDate = now.Add(Month)
	cpn.Once = true
	cpn.Enabled = true
	cpn.Amount = 500

	cpn.MustPut()

	prod := product.New(db)
	prod.Slug = "doge-shirt"
	prod.GetOrCreate("Slug=", prod.Slug)

	cpn = coupon.New(db)
	cpn.Code_ = strings.ToUpper("FREE-DOGE")
	cpn.GetOrCreate("Code=", cpn.Code_)
	cpn.Name = "Free DogeShirt"
	cpn.Type = "free-item"
	cpn.EndDate = now.Add(Month)
	cpn.Once = true
	cpn.Enabled = true
	cpn.FreeProductId = prod.Id()
	cpn.FreeQuantity = 1

	cpn.MustPut()

	cpn = coupon.New(db)
	cpn.Code_ = strings.ToUpper("NO-DOGE-LEFT-BEHIND")
	cpn.GetOrCreate("Code=", cpn.Code_)
	cpn.Dynamic = true
	cpn.Limit = 1
	cpn.Name = "Free DogeShirt"
	cpn.Type = "free-item"
	cpn.EndDate = now.Add(Month)
	cpn.Once = true
	cpn.Enabled = true
	cpn.FreeProductId = prod.Id()
	cpn.FreeQuantity = 1

	cpn.MustPut()

	return cpn
})
View Source
var Discount = New("discount", func(c *gin.Context) *discount.Discount {

	db := getNamespaceDb(c)

	prod := product.New(db)
	prod.Slug = "batman"
	prod.GetOrCreate("Slug=", prod.Slug)
	prod.Name = "Batman T-shirt"
	prod.Headline = "Batman."
	prod.Description = "It's a batman t-shirt."
	prod.Options = []*product.Option{
		&product.Option{
			Name:   "Size",
			Values: []string{"Batwing"},
		},
		&product.Option{
			Name:   "Size",
			Values: []string{"Batmobile"},
		},
	}
	prod.Price = 9900
	prod.Currency = currency.USD
	prod.MustPut()

	dis := discount.New(db)
	dis.Name = "Bulk Discount"
	dis.Type = discount.Bulk
	dis.GetOrCreate("Name=", dis.Name)
	dis.Scope.Type = scope.Organization
	dis.Target.Type = target.Product
	dis.Target.ProductId = prod.Id()

	rule1 := discount.Rule{
		Trigger: rule.Trigger{
			Quantity: rule.Quantity{
				Start: 2,
			},
		},
		Action: rule.Action{
			Discount: rule.Discount{
				Flat: 5,
			},
		},
	}

	rule2 := discount.Rule{}
	rule2.Trigger.Quantity.Start = 3
	rule2.Action.Discount.Flat = 16

	dis.Rules = []discount.Rule{rule1, rule2}
	dis.MustUpdate()

	return dis
})
View Source
var Form = New("form", func(c *gin.Context) *form.Form {
	db := getNamespaceDb(c)

	f := form.New(db)

	f.Name = "Such Tees Newsletter"
	f.SendWelcome = true
	f.Type = "signup"

	f.EmailList.Id = "cc383800a7"
	f.EmailList.Enabled = true

	f.ThankYou.Type = thankyou.Redirect
	f.ThankYou.Url = "http://suchtees.com/thanks/"
	f.Facebook.Id = "6031480185266"
	f.Facebook.Value = "0.00"
	f.Facebook.Currency = "USD"

	f.Google.Category = "Subscription"
	f.Google.Name = "Newsletter Sign-up"

	f.MustPut()

	return f
})
View Source
var Funnel = New("espy-test-funnel", func(c *gin.Context) *funnel.Funnel {
	db := getNamespaceDb(c)

	f := funnel.New(db)
	f.Name = "Boring Funnel"
	f.Events = [][]string{
		[]string{
			"click_1",
		},
		[]string{
			"click_2",
		},
		[]string{
			"click_3",
		},
	}

	f.MustPut()

	return f
})
View Source
var GenerateTestBitcoinTransaction = New("generate-test-bitcoin-transaction", func(c *gin.Context) {
	db := datastore.New(c)
	ctx := db.Context

	w := wallet.New(db)
	w.Id_ = "test-btc-wallet"
	w.UseStringKey = true
	w.GetOrCreate("Id_=", "test-btc-wallet")

	if len(w.Accounts) == 0 {
		if _, err := w.CreateAccount("Test input account", blockchains.BitcoinTestnetType, []byte(config.Bitcoin.TestPassword)); err != nil {
			panic(err)
		}
		if _, err := w.CreateAccount("Test output account 1", blockchains.BitcoinTestnetType, []byte(config.Bitcoin.TestPassword)); err != nil {
			panic(err)
		}
		if _, err := w.CreateAccount("Test output account 2", blockchains.BitcoinTestnetType, []byte(config.Bitcoin.TestPassword)); err != nil {
			panic(err)
		}
	}

	sender, ok := w.GetAccountByName("Test input account")
	if !ok {
		panic(errors.New("Sender Account Not Found."))
	}
	receiver1, ok := w.GetAccountByName("Test output account 1")
	if !ok {
		panic(errors.New("Sender Account Not Found."))
	}
	receiver2, ok := w.GetAccountByName("Test output account 2")
	if !ok {
		panic(errors.New("Sender Account Not Found."))
	}

	log.Info("Accounts Found", ctx)
	log.Info("Sender Address", sender.Address)
	log.Info("Receiver 1 Address", receiver1.Address)
	log.Info("Receiver 2 Address", receiver2.Address)
	if err := sender.Decrypt([]byte(config.Bitcoin.TestPassword)); err != nil {
		panic(err)
	}
	if err := receiver1.Decrypt([]byte(config.Bitcoin.TestPassword)); err != nil {
		panic(err)
	}
	if err := receiver2.Decrypt([]byte(config.Bitcoin.TestPassword)); err != nil {
		panic(err)
	}

	in := []bitcoin.Origin{bitcoin.Origin{TxId: "5b60d0684a8201ddac20f713782a1f03682b508e90d99d0887b4114ad4ccfd2c", OutputIndex: 0}}
	out := []bitcoin.Destination{bitcoin.Destination{Value: 1000, Address: receiver1.Address}, bitcoin.Destination{Value: 5000, Address: receiver2.Address}}
	senderAccount := bitcoin.Sender{
		PrivateKey: sender.PrivateKey,
		PublicKey:  sender.PublicKey,
		Address:    sender.Address,
	}

	client := bitcoin.New(db.Context, config.Bitcoin.TestNetNodes[0], config.Bitcoin.TestNetUsernames[0], config.Bitcoin.TestNetPasswords[0])

	log.Info("Created Bitcoin client.")

	rawTrx, _ := bitcoin.CreateTransaction(client, in, out, senderAccount, 0)

	log.Info("Raw transaction hex: %v", rawTrx)

	log.Info("Not sending raw transaction because this is a generation Fixture. Check the Send-bitcoin-transaction to actually send it to the node.")
})
View Source
var GetTestBitcoinTransaction = New("test-bitcoin-gettransaction", func(c *gin.Context) {
	db := datastore.New(c)

	client := bitcoin.New(db.Context, config.Bitcoin.TestNetNodes[0], config.Bitcoin.TestNetUsernames[0], config.Bitcoin.TestNetPasswords[0])
	log.Info("Created Bitcoin client.")

	res, err := client.GetRawTransaction("5b60d0684a8201ddac20f713782a1f03682b508e90d99d0887b4114ad4ccfd2c")
	if err != nil {
		panic(err)
	}

	log.Info("Btcd Node Response: %v", "", res)
})
View Source
var Order = New("order", func(c *gin.Context) *order.Order {
	db := getNamespaceDb(c)

	u := UserCustomer(c)
	p := Product(c)
	Coupon(c)

	ord := order.New(db)
	ord.UserId = u.Id()
	ord.GetOrCreate("UserId=", ord.UserId)

	ord.ShippingAddress.Name = "Jackson Shirts"
	ord.ShippingAddress.Line1 = "1234 Kansas Drive"
	ord.ShippingAddress.City = "Overland Park"

	ctr, _ := country.FindByISO3166_2("US")
	sd, _ := ctr.FindSubDivision("Kansas")

	ord.ShippingAddress.State = sd.Code
	ord.ShippingAddress.Country = ctr.Codes.Alpha2
	ord.ShippingAddress.PostalCode = "66212"

	ord.Currency = currency.USD
	ord.Items = []LineItem{
		LineItem{
			ProductCachedValues: productcachedvalues.ProductCachedValues{
				Price: currency.Cents(100),
			},
			ProductId: p.Id(),
			Quantity:  20,
		},
	}

	ord.CouponCodes = []string{"SUCH-COUPON", "FREE-DOGE"}
	ord.UpdateAndTally(nil)
	ord.MustPut()

	return ord
})
View Source
var Organization = New("organization", func(c *gin.Context) *organization.Organization {
	BlockchainNamespace(c)

	db := datastore.New(c)

	usr := User(c).(*user.User)

	org := organization.New(db)
	org.Name = "suchtees"
	org.SecretKey = []byte("prettyprettyteesplease")
	org.GetOrCreate("Name=", org.Name)

	org.FullName = "Such Tees, Inc."
	org.Owners = []string{usr.Id()}
	org.Websites = []website.Website{website.Website{Type: website.Production, Url: "http://suchtees.com"}}
	org.AddDefaultTokens()

	org.Stripe.Test.UserId = "acct_16fNBDH4ZOGOmFfW"
	org.Stripe.Test.AccessToken = ""
	org.Stripe.Test.PublishableKey = "pk_test_HHiaCsBYlyfI45xtAvIAsjRe"
	org.Stripe.Test.RefreshToken = ""

	org.AuthorizeNet.Sandbox.LoginId = ""
	org.AuthorizeNet.Sandbox.TransactionKey = ""
	org.AuthorizeNet.Sandbox.Key = "Simon"

	org.Ethereum.Address = "0xf2fccc0198fc6b39246bd91272769d46d2f9d43b"
	org.Bitcoin.Address = ""
	org.Bitcoin.TestAddress = "mrPFGX5ViUZk2s8i5soBCkrFVzRwngK8DQ"

	org.Stripe.Live.UserId = org.Stripe.Test.UserId
	org.Stripe.Live.AccessToken = org.Stripe.Test.AccessToken
	org.Stripe.Live.PublishableKey = org.Stripe.Test.PublishableKey
	org.Stripe.Live.RefreshToken = org.Stripe.Test.RefreshToken

	org.Stripe.UserId = org.Stripe.Test.UserId
	org.Stripe.AccessToken = org.Stripe.Test.AccessToken
	org.Stripe.PublishableKey = org.Stripe.Test.PublishableKey
	org.Stripe.RefreshToken = org.Stripe.Test.RefreshToken

	org.Paypal.ConfirmUrl = "http://hanzo.ai"
	org.Paypal.CancelUrl = "http://hanzo.ai"

	org.Paypal.Live.Email = "dev@hanzo.ai"
	org.Paypal.Live.SecurityUserId = "dev@hanzo.ai"
	org.Paypal.Live.ApplicationId = "APP-80W284485P519543T"
	org.Paypal.Live.SecurityPassword = ""
	org.Paypal.Live.SecuritySignature = ""

	org.Paypal.Test.Email = "dev@hanzo.ai"
	org.Paypal.Test.SecurityUserId = "dev@hanzo.ai"
	org.Paypal.Test.ApplicationId = "APP-80W284485P519543T"
	org.Paypal.Test.SecurityPassword = ""
	org.Paypal.Test.SecuritySignature = ""

	org.WalletPassphrase = "1234"

	if false {
		w, _ := org.GetOrCreateWallet(org.Db)
		a1, _ := w.CreateAccount("Test Ethereum", blockchains.EthereumRopstenType, []byte(org.WalletPassphrase))
		a1.Withdrawable = true
		a2, _ := w.CreateAccount("Test Bitcoin", blockchains.BitcoinTestnetType, []byte(org.WalletPassphrase))
		a2.Withdrawable = true
		w.MustUpdate()
	}

	integrations := []Integration{
		Integration{
			Type: "facebook-pixel",
			Id:   "920910517982389",
		},
		Integration{
			Type: "google-analytics",
			Id:   "UA-65099214-1",
		},
	}
	org.Analytics = Analytics{Integrations: integrations}

	org.MustPut()

	if org.DefaultStore == "" {
		nsdb := datastore.New(org.Namespaced(org.Context()))

		stor := store.New(nsdb)
		stor.GetOrCreate("Name=", "Default")
		stor.Name = "Default"
		stor.Currency = org.Currency
		stor.MustUpdate()

		trs := taxrates.New(nsdb)
		trs.GetOrCreate("StoreId=", stor.Id())
		trs.StoreId = stor.Id()
		trs.MustCreate()

		srs := shippingrates.New(nsdb)
		srs.GetOrCreate("StoreId=", stor.Id())
		srs.StoreId = stor.Id()
		srs.MustCreate()

		org.DefaultStore = stor.Id()
		org.MustUpdate()
	}

	stor, _ := org.GetDefaultStore()

	trs, _ := stor.GetTaxRates()
	trs.GeoRates = []taxrates.GeoRate{
		taxrates.GeoRate{
			GeoRate: georate.New(
				"US",
				"MO",
				"",
				"64108",
				0,
				0,
				0.08475,
				0,
			),
		},
		taxrates.GeoRate{
			GeoRate: georate.New(
				"US",
				"MO",
				"",
				"",
				0,
				0,
				0.04225,
				0,
			),
		},
	}

	trs.MustUpdate()

	srs, _ := stor.GetShippingRates()
	srs.GeoRates = []shippingrates.GeoRate{
		shippingrates.GeoRate{
			GeoRate: georate.New(
				"US",
				"",
				"",
				"",
				0,
				0,
				0,
				499,
			),
		},
		shippingrates.GeoRate{
			GeoRate: georate.New(
				"",
				"",
				"",
				"",
				0,
				0,
				0,
				999,
			),
		},
	}

	srs.MustUpdate()

	usr.Organizations = []string{org.Id()}
	usr.MustPut()
	return org
})
View Source
var Plan = New("plan", func(c *gin.Context) *plan.Plan {

	db := getNamespaceDb(c)

	pln := plan.New(db)
	pln.Slug = "much-shirts"
	pln.GetOrCreate("Slug=", pln.Slug)
	pln.Name = "Much Monthly Shirt"
	pln.Description = `wow
	      such shirt
	much tee

			nice shop

	 so hip

	    so doge
	`
	pln.Price = 2000
	pln.Currency = currency.USD
	pln.Interval = Monthly
	pln.IntervalCount = 1

	pln.MustPut()

	return pln
})
View Source
var PlatformWallet = New("platform-wallet", func(c *gin.Context) *wallet.Wallet {
	BlockchainNamespace(c)

	db := datastore.New(c)

	w := wallet.New(db)
	w.Id_ = "platform-wallet"
	w.UseStringKey = true
	w.GetOrCreate("Id_=", "platform-wallet")

	if _, ok := w.GetAccountByName("Ethereum Ropsten Test Account"); !ok {
		if _, err := w.CreateAccount("Ethereum Ropsten Test Account", blockchains.EthereumRopstenType, []byte(config.Ethereum.TestPassword)); err != nil {
			panic(err)
		}
	}

	if _, ok := w.GetAccountByName("Ethereum Deposit Account"); !ok {
		if _, err := w.CreateAccount("Ethereum Deposit Account", blockchains.EthereumType, []byte(config.Ethereum.DepositPassword)); err != nil {
			panic(err)
		}
	}

	if _, ok := w.GetAccountByName("Bitcoin Test Account"); !ok {
		if _, err := w.CreateAccount("Bitcoin Test Account", blockchains.BitcoinTestnetType, []byte(config.Bitcoin.TestPassword)); err != nil {
			panic(err)
		}
	}

	if _, ok := w.GetAccountByName("Bitcoin Deposit Account"); !ok {
		if _, err := w.CreateAccount("Bitcoin Deposit Account", blockchains.BitcoinType, []byte(config.Bitcoin.DepositPassword)); err != nil {
			panic(err)
		}
	}

	return w
})

This wallet stores special platform level Addresses

View Source
var Product = New("product", func(c *gin.Context) *product.Product {

	db := getNamespaceDb(c)

	prod := product.New(db)
	prod.Slug = "doge-shirt"
	prod.GetOrCreate("Slug=", prod.Slug)
	prod.Name = "Such T-shirt"
	prod.Headline = "wow  such shirt  much tee"
	prod.Description = `wow
	      such shirt
	much tee

			nice shop

	 so hip

	    so doge
	`
	prod.Options = []*product.Option{
		&product.Option{
			Name:   "Size",
			Values: []string{"Much", "Wow"},
		},
	}
	prod.Price = 2000
	prod.Currency = currency.USD
	prod.MustPut()

	prod = product.New(db)
	prod.Slug = "sad-keanu-shirt"
	prod.GetOrCreate("Slug=", prod.Slug)
	prod.Name = "Sad Keanu T-shirt"
	prod.Headline = "Oh Keanu"
	prod.Description = "Sad Keanu is sad."
	prod.Options = []*product.Option{
		&product.Option{
			Name:   "Size",
			Values: []string{"Sadness"},
		},
	}
	prod.Price = 2500
	prod.Currency = currency.USD
	prod.MustPut()

	return prod
})
View Source
var Referral = New("referral", func(c *gin.Context) *referral.Referral {

	db := getNamespaceDb(c)

	ord := Order(c)
	u := User(c)

	ref := referral.New(db)
	ref.UserId = u.Id()
	ref.OrderId = ord.Id()
	ref.GetOrCreate("OrderId=", ref.OrderId)
	ref.MustPut()

	return ref
})
View Source
var Referrer = New("referrer", func(c *gin.Context) *referrer.Referrer {

	db := getNamespaceDb(c)

	u := User(c)

	ref := referrer.New(db)
	ref.UserId = u.Id()
	ref.GetOrCreate("UserId=", ref.UserId)
	ref.Program.Triggers = []int{0}
	ref.Program.Actions = []referralprogram.Action{referralprogram.Action{Type: referralprogram.StoreCredit}}
	ref.Program.Actions[0].CreditAction = referralprogram.CreditAction{Currency: currency.USD, Amount: currency.Cents(1000)}
	ref.MustPut()

	return ref
})
View Source
var SECDemo = New("sec-demo", func(c *gin.Context) *organization.Organization {
	db := datastore.New(c)

	org := organization.New(db)
	org.Name = "sec-demo"
	org.GetOrCreate("Name=", org.Name)

	u := user.New(db)
	u.Email = "sec@hanzo.ai"
	u.GetOrCreate("Email=", u.Email)
	u.FirstName = "SEC"
	u.LastName = "User"
	u.Organizations = []string{org.Id()}
	u.PasswordHash, _ = password.Hash("secdemo2")
	u.Put()

	org.FullName = "SEC DEMO"
	org.Owners = []string{u.Id()}
	org.Websites = []website.Website{website.Website{Type: website.Production, Url: "https://sec.hanzo.ai"}}
	org.SecretKey = []byte("XzJn6Asyd9ZVSuaCDHjxj3tuhAb6FPLnzZ5VU9Md6VwsMrnCHrkcz8ZBBxqMURJD")
	org.AddDefaultTokens()

	org.Fees.Card.Flat = 50
	org.Fees.Card.Percent = 0.05
	org.Fees.Affiliate.Flat = 30
	org.Fees.Affiliate.Percent = 0.30
	org.Fees.Ethereum.Flat = 0
	org.Fees.Ethereum.Percent = 0.06

	org.Email.Enabled = true
	org.Email.Defaults.From = email.Email{
		Name:    "Hanzo",
		Address: "info@hanzo.ai",
	}

	org.SignUpOptions.ImmediateLogin = true
	org.SignUpOptions.AccountsEnabledByDefault = true

	eth := &integration.Integration{
		Type:    integration.EthereumType,
		Enabled: true,
		Ethereum: integration.Ethereum{
			Address:     "0xf8f59f0269c4f6d7b5c5ab98d70180eaa0c7507e",
			TestAddress: "0xf8f59f0269c4f6d7b5c5ab98d70180eaa0c7507e",
		},
	}

	if len(org.Integrations.FilterByType(eth.Type)) == 0 {
		org.Integrations = org.Integrations.MustAppend(eth)
	}

	org.MustUpdate()

	return org
})
View Source
var SendTestBitcoinOrder = New("send-test-bitcoin-order", func(c *gin.Context) {
	org := Organization(c).(*organization.Organization)
	accessToken := org.MustGetTokenByName("test-published-key")

	ctx := org.Db.Context

	db := getNamespaceDb(c)

	u := UserCustomer(c)

	ord := order.New(db)
	ord.UserId = u.Id()
	ord.ShippingAddress.Name = "Jackson Shirts"
	ord.ShippingAddress.Line1 = "1234 Kansas Drive"
	ord.ShippingAddress.City = "Overland Park"

	ctr, _ := country.FindByISO3166_2("US")
	sd, _ := ctr.FindSubDivision("Kansas")

	ord.ShippingAddress.State = sd.Code
	ord.ShippingAddress.Country = ctr.Codes.Alpha2
	ord.ShippingAddress.PostalCode = "66212"
	ord.Type = accounts.BitcoinType

	ord.Currency = currency.BTC
	ord.Subtotal = currency.Cents(1e5)
	ord.Mode = order.ContributionMode

	ch := checkout.Authorization{
		Order: ord,
	}

	j := json.Encode(ch)

	log.Info("Sending To %s", "https://api.hanzo.ai/checkout/authorize/", c)
	log.Info("Sending Test Order: %s", j, c)

	client := &http.Client{}
	req, err := http.NewRequestWithContext(ctx, "POST", "https://api.hanzo.ai/checkout/authorize/", strings.NewReader(j))
	if err != nil {
		panic(err)
	}

	req.Header.Set("Content-Type", "application/json")
	req.Header.Set("Authorization", accessToken.String)

	if res, err := client.Do(req); err != nil {
		panic(err)
	} else {
		log.Info("Hanzo Test Response: %v", res, c)
	}
})
View Source
var SendTestBitcoinTransaction = New("send-test-bitcoin-transaction", func(c *gin.Context) {
	transactionId := "62e3949e3e143bfc2ce904a8fe68532962444870360320394c3d358666ce453d"

	db := datastore.New(c)
	ctx := db.Context

	w := wallet.New(db)
	w.Id_ = "test-btc-wallet"
	w.UseStringKey = true
	w.GetOrCreate("Id_=", "test-btc-wallet")

	if len(w.Accounts) == 0 {
		if _, err := w.CreateAccount("Test input account", blockchains.BitcoinTestnetType, []byte(config.Bitcoin.TestPassword)); err != nil {
			panic(err)
		}
		if _, err := w.CreateAccount("Test output account 1", blockchains.BitcoinTestnetType, []byte(config.Bitcoin.TestPassword)); err != nil {
			panic(err)
		}
		if _, err := w.CreateAccount("Test output account 2", blockchains.BitcoinTestnetType, []byte(config.Bitcoin.TestPassword)); err != nil {
			panic(err)
		}
	}

	sender, ok := w.GetAccountByName("Test input account")
	if !ok {
		panic(errors.New("Sender Account Not Found."))
	}
	receiver1, ok := w.GetAccountByName("Test output account 1")
	if !ok {
		panic(errors.New("Sender Account Not Found."))
	}
	receiver2, ok := w.GetAccountByName("Test output account 2")
	if !ok {
		panic(errors.New("Sender Account Not Found."))
	}

	log.Info("Accounts Found", ctx)
	log.Info("Sender Address", sender.Address)
	log.Info("Receiver 1 Address", receiver1.Address)
	log.Info("Receiver 2 Address", receiver2.Address)
	if err := sender.Decrypt([]byte(config.Bitcoin.TestPassword)); err != nil {
		panic(err)
	}
	if err := receiver1.Decrypt([]byte(config.Bitcoin.TestPassword)); err != nil {
		panic(err)
	}
	if err := receiver2.Decrypt([]byte(config.Bitcoin.TestPassword)); err != nil {
		panic(err)
	}

	in := []bitcoin.Origin{
		bitcoin.Origin{TxId: transactionId, OutputIndex: 0},
	}
	out := []bitcoin.Destination{bitcoin.Destination{Value: 100000, Address: receiver1.Address}, bitcoin.Destination{Value: 500000, Address: receiver2.Address}}
	senderAccount := bitcoin.Sender{
		PrivateKey: sender.PrivateKey,
		PublicKey:  sender.PublicKey,
		Address:    sender.Address,
	}

	client := bitcoin.New(db.Context, config.Bitcoin.TestNetNodes[0], config.Bitcoin.TestNetUsernames[0], config.Bitcoin.TestNetPasswords[0])
	log.Info("Created Bitcoin client.")

	rawTrx, err := bitcoin.CreateTransaction(client, in, out, senderAccount, 0)
	if err != nil {
		panic(err)
	}

	log.Info("Raw transaction hex: %v", rawTrx)
	res, err := client.SendRawTransaction(rawTrx)
	if err != nil {
		panic(err)
	}

	log.Info("Btcd Node Response: %v", "", res)
})
View Source
var SendTestEthereumOrder = New("send-test-ethereum-order", func(c *gin.Context) {
	org := Organization(c).(*organization.Organization)
	accessToken := org.MustGetTokenByName("test-published-key")

	ctx := org.Db.Context

	db := getNamespaceDb(c)

	u := UserCustomer(c)

	ord := order.New(db)
	ord.UserId = u.Id()
	ord.ShippingAddress.Name = "Jackson Shirts"
	ord.ShippingAddress.Line1 = "1234 Kansas Drive"
	ord.ShippingAddress.City = "Overland Park"

	ctr, _ := country.FindByISO3166_2("US")
	sd, _ := ctr.FindSubDivision("Kansas")

	ord.ShippingAddress.State = sd.Code
	ord.ShippingAddress.Country = ctr.Codes.Alpha2
	ord.ShippingAddress.PostalCode = "66212"
	ord.Type = accounts.EthereumType

	ord.Currency = currency.ETH
	ord.Subtotal = currency.Cents(100000000)
	ord.Mode = order.ContributionMode

	ch := checkout.Authorization{
		Order: ord,
	}

	j := json.Encode(ch)

	log.Info("Sending To %s", "https://api.hanzo.ai/checkout/authorize/", c)
	log.Info("Sending Test Order: %s", j, c)

	client := &http.Client{}
	req, err := http.NewRequestWithContext(ctx, "POST", "https://api.hanzo.ai/checkout/authorize/", strings.NewReader(j))
	if err != nil {
		panic(err)
	}

	req.Header.Set("Content-Type", "application/json")
	req.Header.Set("Authorization", accessToken.String)

	if res, err := client.Do(req); err != nil {
		panic(err)
	} else {
		log.Info("Hanzo Test Response: %v", res, c)
	}
})
View Source
var SendTestEthereumTransaction = New("send-test-ethereum-transaction", func(c *gin.Context) {
	db := datastore.New(c)
	ctx := db.Context

	w := wallet.New(db)
	w.Id_ = "test-customer-wallet"
	w.UseStringKey = true
	w.GetOrCreate("Id_=", "test-customer-wallet")

	if len(w.Accounts) == 0 {
		if _, err := w.CreateAccount("Test Customer Account", blockchains.EthereumRopstenType, []byte(config.Ethereum.TestPassword)); err != nil {
			panic(err)
		}
	}

	pw := wallet.New(db)
	pw.GetOrCreate("Id_=", "platform-wallet")

	account, ok := pw.GetAccountByName("Ethereum Ropsten Test Account")
	if !ok {
		panic(errors.New("Platform Account Not Found."))
	}

	log.Info("Account Found", ctx)
	if err := account.Decrypt([]byte(config.Ethereum.TestPassword)); err != nil {
		panic(err)
	}

	client := ethereum.New(db.Context, config.Ethereum.TestNetNodes[0])

	hash, err := client.SendTransaction(ethereum.Ropsten, account.PrivateKey, account.Address, w.Accounts[0].Address, big.NewInt(1000000000000000), big.NewInt(0), big.NewInt(0), []byte{})
	if err != nil {
		panic(err)
	}

	log.Info("Geth Node Response: %v", hash, c)
})
View Source
var Store = New("store", func(c *gin.Context) *store.Store {

	db := getNamespaceDb(c)

	stor := store.New(db)
	stor.Slug = "suchtees"
	stor.GetOrCreate("Slug=", stor.Slug)

	stor.Name = "JPY Store"
	stor.Domain = "suchtees.com"
	stor.Prefix = "/"
	stor.Currency = currency.JPY
	stor.TaxNexus = []Address{Address{Line1: "123 Such St", City: "Tee City"}, Address{Line1: "456 Noo Ln", City: "Memetown"}}

	prod := Product(c).(*product.Product)
	price := currency.Cents(30000)
	stor.Listings[prod.Id()] = store.Listing{
		ProductId: prod.Id(),
		Price:     &price,
	}

	stor.MustPut()
	return stor
})
View Source
var Submission = New("submission", func(c *gin.Context) *submission.Submission {
	db := getNamespaceDb(c)

	sub := submission.New(db)
	sub.Email = "fan@suchfan.com"
	sub.Metadata["message"] = "Hi I am a fan!"

	sub.MustPut()

	return sub
})
View Source
var Token = New("token", func(c *gin.Context) *token.Token {
	db := getNamespaceDb(c)

	token := token.New(db)
	token.Email = "test@test.com"
	token.GetOrCreate("Email=", token.Email)
	token.UserId = "fake"
	token.MustPut()

	return token
})
View Source
var Transaction = New("transaction", func(c *gin.Context) *transaction.Transaction {

	db := getNamespaceDb(c)

	u := User(c)

	tran := transaction.New(db)
	tran.DestinationId = u.Id()
	tran.GetOrCreate("DestinationId=", tran.DestinationId)
	tran.Type = "deposit"
	tran.Currency = currency.USD
	tran.Amount = 1000
	tran.MustPut()

	return tran
})
View Source
var User = New("user", func(c *gin.Context) *user.User {
	db := datastore.New(c)

	usr := user.New(db)
	usr.Email = "dev@hanzo.ai"
	usr.GetOrCreate("Email=", usr.Email)

	usr.FirstName = "Jackson"
	usr.LastName = "Shirts"
	usr.Phone = "(999) 999-9999"
	usr.PasswordHash, _ = password.Hash("suchtees")
	usr.MustPut()
	return usr
})
View Source
var UserCustomer = New("user-customer", func(c *gin.Context) *user.User {
	db := getNamespaceDb(c)

	usr := user.New(db)
	usr.Email = "dev@hanzo.ai"
	usr.GetOrCreate("Email=", usr.Email)

	usr.FirstName = "Jackson"
	usr.LastName = "Shirts"
	usr.Phone = "(999) 999-9999"
	usr.PasswordHash, _ = password.Hash("suchtees")
	usr.MustPut()
	return usr
})
View Source
var Variant = New("variant", func(c *gin.Context) *variant.Variant {

	db := getNamespaceDb(c)

	prod := Product(c).(*product.Product)

	v := variant.New(db)
	v.Parent = prod.Key()
	v.SKU = "T-SHIRT-M"
	v.GetOrCreate("SKU=", v.SKU)
	v.ProductId = prod.Id()
	v.Options = []variant.Option{variant.Option{Name: "Size", Value: "Much"}}
	v.ProductId = prod.Id()
	v.Price = 2000
	v.Currency = currency.USD
	v.MustPut()

	v2 := variant.New(db)
	v2.Parent = prod.Key()
	v2.SKU = "T-SHIRT-W"
	v2.GetOrCreate("SKU=", v2.SKU)
	v2.ProductId = prod.Id()
	v2.Options = []variant.Option{variant.Option{Name: "Size", Value: "Wow"}}
	v2.ProductId = prod.Id()
	v2.Price = 2000
	v2.Currency = currency.USD
	v2.MustPut()

	prod.Variants = []*variant.Variant{v, v2}
	prod.Put()

	return v
})

Functions

func New

func New(name string, fn interface{}) func(c context.Context) mixin.Entity

Types

type Fixture

type Fixture struct {
	// contains filtered or unexported fields
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL