mirror of
https://github.com/hanzoai/commerce.git
synced 2026-10-30 15:08:42 +00:00
Multi-tenant commerce and billing: orders, subscriptions, invoices, plans, usage metering and a credit ledger. One Go binary. MIT OR Apache-2.0. Claude-Session: https://claude.ai/code/session_01SAtaDFm8VDiWrhYHNNtxMw
30 lines
715 B
Go
30 lines
715 B
Go
package paypal
|
|
|
|
import (
|
|
"github.com/hanzoai/commerce/log"
|
|
"github.com/hanzoai/commerce/models/order"
|
|
"github.com/hanzoai/commerce/models/organization"
|
|
"github.com/hanzoai/commerce/models/payment"
|
|
"github.com/hanzoai/commerce/models/user"
|
|
"github.com/hanzoai/commerce/thirdparty/paypal"
|
|
)
|
|
|
|
func Authorize(org *organization.Organization, ord *order.Order, usr *user.User, pay *payment.Payment) error {
|
|
ctx := ord.Context()
|
|
|
|
client := paypal.New(ctx)
|
|
|
|
// Do authorization
|
|
payKey, err := client.GetPayKey(pay, ord, org)
|
|
if err != nil {
|
|
log.Warn("Failed to authorize payment '%s'", pay.Id())
|
|
log.JSON(pay)
|
|
return err
|
|
}
|
|
|
|
pay.Account.PayKey = payKey
|
|
usr.Accounts.PayPal.PayKey = payKey
|
|
|
|
return nil
|
|
}
|