diff --git a/README.md b/README.md index dfdddf9..8c6e04d 100644 --- a/README.md +++ b/README.md @@ -48,6 +48,9 @@ go mod tidy ### Transfer - [x] transfer balance to a connected Stripe account + +### Transaction + - [x] get details of a balance transaction ## Usage diff --git a/transaction.go b/transaction.go new file mode 100644 index 0000000..85b0cd2 --- /dev/null +++ b/transaction.go @@ -0,0 +1,15 @@ +package stripego + +import ( + "github.com/stripe/stripe-go/v74" + "github.com/stripe/stripe-go/v74/balancetransaction" +) + +// GetBalanceTx - get details of a balance transaction in Stripe +func GetBalanceTx(sk, bTxID string) (txn *stripe.BalanceTransaction, err error) { + // stripe secret key + stripe.Key = sk + + txn, err = balancetransaction.Get(bTxID, nil) + return +} diff --git a/transaction_test.go b/transaction_test.go new file mode 100644 index 0000000..64566d7 --- /dev/null +++ b/transaction_test.go @@ -0,0 +1,39 @@ +package stripego_test + +import ( + "encoding/json" + "os" + "strings" + "testing" + + "github.com/pilinux/stripego" + "github.com/stripe/stripe-go/v74" +) + +var BTxID string + +func TestGetBalanceTx(t *testing.T) { + StripeSK = strings.TrimSpace(os.Getenv("STRIPE_SK")) + Currency = strings.TrimSpace(os.Getenv("CURRENCY")) + BTxID = strings.TrimSpace(os.Getenv("BALANCE_TRANSACTION_ID")) + + txn, err := stripego.GetBalanceTx(StripeSK, BTxID) + if err != nil { + t.Errorf("got error when retrieving a transaction details: %v", err) + return + } + + res := &stripe.BalanceTransaction{} + err = json.Unmarshal(txn.LastResponse.RawJSON, &res) + if err != nil { + t.Errorf("got error when unmarshalling transaction details: %v", err) + return + } + + if res.ID != BTxID { + t.Errorf("balance transaction IDs do not match") + } + if res.Currency != stripe.Currency(Currency) { + t.Errorf("got: %v, want: %v", res.Currency, stripe.Currency(Currency)) + } +} diff --git a/transfer.go b/transfer.go index a0ada3c..dbc3e8f 100644 --- a/transfer.go +++ b/transfer.go @@ -2,7 +2,6 @@ package stripego import ( "github.com/stripe/stripe-go/v74" - "github.com/stripe/stripe-go/v74/balancetransaction" transfer "github.com/stripe/stripe-go/v74/transfer" ) @@ -14,12 +13,3 @@ func TransferBalance(sk string, tp *stripe.TransferParams) (tRes *stripe.Transfe tRes, err = transfer.New(tp) return } - -// GetBalanceTx - get details of a balance transaction in Stripe -func GetBalanceTx(sk, bTxID string) (txn *stripe.BalanceTransaction, err error) { - // stripe secret key - stripe.Key = sk - - txn, err = balancetransaction.Get(bTxID, nil) - return -} diff --git a/transfer_test.go b/transfer_test.go index 8ad55cd..702e65f 100644 --- a/transfer_test.go +++ b/transfer_test.go @@ -13,7 +13,6 @@ import ( var Destination string var TransferObject string var TransferAmount int64 -var BTxID string func TestTransferBalance(t *testing.T) { StripeSK = strings.TrimSpace(os.Getenv("STRIPE_SK")) @@ -35,7 +34,6 @@ func TestTransferBalance(t *testing.T) { t.Errorf("got error when initiating balance transfer: %v", err) return } - BTxID = tRes.BalanceTransaction.ID res := &stripe.Transfer{} err = json.Unmarshal(tRes.LastResponse.RawJSON, &res) @@ -62,25 +60,3 @@ func TestTransferBalance(t *testing.T) { t.Errorf("destination IDs do not match") } } - -func TestGetBalanceTx(t *testing.T) { - txn, err := stripego.GetBalanceTx(StripeSK, BTxID) - if err != nil { - t.Errorf("got error when retrieving a transaction details: %v", err) - return - } - - res := &stripe.BalanceTransaction{} - err = json.Unmarshal(txn.LastResponse.RawJSON, &res) - if err != nil { - t.Errorf("got error when unmarshalling transaction details: %v", err) - return - } - - if res.ID != BTxID { - t.Errorf("balance transaction IDs do not match") - } - if res.Currency != stripe.Currency(Currency) { - t.Errorf("got: %v, want: %v", res.Currency, stripe.Currency(Currency)) - } -}