mirror of
https://github.com/hanzoai/commerce.git
synced 2026-10-30 15:08:42 +00:00
EmbedConfig.Ceiling is declared by the host as Born is: Test where the network holds no real money, "" or Live for no cap, and any other value caps at Test. Under a Test ceiling TestMode is true for every org, a record marked Live included, so it charges sandbox credentials, writes the test books and publishes the sandbox application. TestMode is the one reading of the mode: the ledger, balance, transaction, library, account and Authorize.Net paths, StripeToken and PayPal read it instead of org.Live, so the ceiling holds on each of them. Co-authored-by: Hanzo Dev <[email protected]>
32 lines
773 B
Go
32 lines
773 B
Go
package balance
|
|
|
|
import (
|
|
"errors"
|
|
|
|
"github.com/hanzoai/commerce/models/order"
|
|
"github.com/hanzoai/commerce/models/organization"
|
|
"github.com/hanzoai/commerce/models/payment"
|
|
"github.com/hanzoai/commerce/models/types/accounts"
|
|
"github.com/hanzoai/commerce/models/user"
|
|
)
|
|
|
|
var InsufficientCredit = errors.New("Insufficient credit")
|
|
|
|
func Authorize(org *organization.Organization, ord *order.Order, usr *user.User, pay *payment.Payment) error {
|
|
// Deprecated
|
|
pay.Type = accounts.BalanceType
|
|
|
|
pay.Account.Type = accounts.BalanceType
|
|
pay.Live = !org.TestMode()
|
|
|
|
if err := usr.CalculateBalances(org.TestMode()); err != nil {
|
|
return err
|
|
}
|
|
|
|
if val, ok := usr.Transactions[ord.Currency]; !ok || val.Balance < ord.Total {
|
|
return InsufficientCredit
|
|
}
|
|
|
|
return nil
|
|
}
|