Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions pkg/model/entity.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions pkg/model/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
16 changes: 10 additions & 6 deletions pkg/service/checkout.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -155,11 +155,15 @@ func CaptureCharge(amount float64, userWallet string, authorizationID string) (c
Amount: usd,
}

capture, err = client.Captures(authorizationID, &request, &params)
capture, err := client.Captures(p.cardAuthorization.AuthID, &request, &params)
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
}
6 changes: 4 additions & 2 deletions pkg/service/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -59,6 +60,7 @@ type transactionProcessingData struct {
chain *Chain
executionRequest *model.ExecutionRequest
cardAuthorization *AuthorizedCharge
cardCapture *payments.CapturesResponse
preBalance *float64
recipientWalletId *string
txId *string
Expand Down Expand Up @@ -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)
}
Expand All @@ -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)
Expand Down