diff --git a/migrations/0005_user-to-platform_contact-to-platform_device-to-instrument_platform.sql b/migrations/0005_user-to-platform_contact-to-platform_device-to-instrument_platform.sql index f2220fdd..cc1036fa 100644 --- a/migrations/0005_user-to-platform_contact-to-platform_device-to-instrument_platform.sql +++ b/migrations/0005_user-to-platform_contact-to-platform_device-to-instrument_platform.sql @@ -45,10 +45,19 @@ ALTER TABLE platform ADD COLUMN domains TEXT[] DEFAULT NULL, -- define which domains can make calls to API (web-to-API) ADD COLUMN ip_addresses TEXT[] DEFAULT NULL; -- define which API ips can make calls (API-to-API) +------------------------------------------------------------------------- +-- TRANSACTION ------------------------------------------------------------- +ALTER TABLE transaction + ADD COLUMN payment_code TEXT DEFAULT ''; ------------------------------------------------------------------------- -- +goose Down +------------------------------------------------------------------------- +-- TRANSACTION ------------------------------------------------------------- +ALTER TABLE transaction + DROP COLUMN IF EXISTS payment_code; + ------------------------------------------------------------------------- -- PLATFORM ------------------------------------------------------------- ALTER TABLE platform diff --git a/pkg/model/entity.go b/pkg/model/entity.go index bc8c0027..57d460fc 100644 --- a/pkg/model/entity.go +++ b/pkg/model/entity.go @@ -186,6 +186,7 @@ type Transaction struct { ProcessingFee string `json:"processingFee,omitempty" db:"processing_fee"` ProcessingFeeAsset string `json:"processingFeeAsset,omitempty" db:"processing_fee_asset"` StringFee string `json:"stringFee,omitempty" db:"string_fee"` + PaymentCode string `json:"paymentCode,omitempty" db:"payment_code"` } type AuthStrategy struct { diff --git a/pkg/model/request.go b/pkg/model/request.go index ca56c48e..f4701046 100644 --- a/pkg/model/request.go +++ b/pkg/model/request.go @@ -31,6 +31,7 @@ type TransactionUpdates struct { ProcessingFee *string `json:"processingFee" db:"processing_fee"` ProcessingFeeAsset *string `json:"processingFeeAsset" db:"processing_fee_asset"` StringFee *string `json:"stringFee" db:"string_fee"` + PaymentCode *string `json:"paymentCode" db:"payment_code"` } type InstrumentUpdates struct { diff --git a/pkg/service/checkout.go b/pkg/service/checkout.go index 62d8910f..da5fd7de 100644 --- a/pkg/service/checkout.go +++ b/pkg/service/checkout.go @@ -138,14 +138,14 @@ func AuthorizeCharge(p transactionProcessingData) (transactionProcessingData, er return p, nil } -func CaptureCharge(amount float64, userWallet string, authorizationID string) (capture *payments.CapturesResponse, err error) { +func CaptureCharge(p transactionProcessingData) (transactionProcessingData, error) { config, err := getConfig() if err != nil { - return nil, common.StringError(err) + return p, common.StringError(err) } client := payments.NewClient(*config) - usd := convertAmount(amount) + usd := convertAmount(p.executionRequest.Quote.TotalUSD) idempotencyKey := checkout.NewIdempotencyKey() params := checkout.Params{ @@ -155,11 +155,15 @@ func CaptureCharge(amount float64, userWallet string, authorizationID string) (c Amount: usd, } - capture, err = client.Captures(authorizationID, &request, ¶ms) + capture, err := client.Captures(p.cardAuthorization.AuthID, &request, ¶ms) if err != nil { - return nil, common.StringError(err) + return p, common.StringError(err) } + p.cardCapture = capture + + // TODO: call action, err = client.Actions(capture.Accepted.ActionID) in another service to check on + // TODO: Create entry for capture in our DB associated with userWallet - return capture, nil + return p, nil } diff --git a/pkg/service/transaction.go b/pkg/service/transaction.go index 936fe7fa..b0a4f772 100644 --- a/pkg/service/transaction.go +++ b/pkg/service/transaction.go @@ -10,6 +10,7 @@ import ( "strings" "time" + "github.com/checkout/checkout-sdk-go/payments" "github.com/pkg/errors" "github.com/String-xyz/string-api/pkg/internal/common" @@ -59,6 +60,7 @@ type transactionProcessingData struct { chain *Chain executionRequest *model.ExecutionRequest cardAuthorization *AuthorizedCharge + cardCapture *payments.CapturesResponse preBalance *float64 recipientWalletId *string txId *string @@ -676,7 +678,7 @@ func (t transaction) tenderTransaction(p transactionProcessingData) (float64, er } func (t transaction) chargeCard(p transactionProcessingData) error { - _, err := CaptureCharge(p.executionRequest.Quote.TotalUSD, p.executionRequest.UserAddress, p.cardAuthorization.AuthID) + p, err := CaptureCharge(p) if err != nil { return common.StringError(err) } @@ -695,7 +697,7 @@ func (t transaction) chargeCard(p transactionProcessingData) error { if err != nil { return common.StringError(err) } - txLeg := model.TransactionUpdates{ReceiptTxLegID: &receiptLeg.ID} + txLeg := model.TransactionUpdates{ReceiptTxLegID: &receiptLeg.ID, PaymentCode: &p.cardCapture.Accepted.ActionID} err = t.repos.Transaction.Update(p.transactionModel.ID, txLeg) if err != nil { return common.StringError(err)