Skip to content

Commit

Permalink
feat: function to retrieve a transaction details
Browse files Browse the repository at this point in the history
  • Loading branch information
pilinux committed Jan 3, 2023
1 parent ecef20b commit 949ac8a
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ go mod tidy
### Transfer

- [x] transfer balance to a connected Stripe account
- [x] get details of a balance transaction

## Usage

Expand Down
10 changes: 10 additions & 0 deletions transfer.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package stripego

import (
"github.com/stripe/stripe-go/v74"
"github.com/stripe/stripe-go/v74/balancetransaction"
transfer "github.com/stripe/stripe-go/v74/transfer"
)

Expand All @@ -13,3 +14,12 @@ 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
}
24 changes: 24 additions & 0 deletions transfer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ 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"))
Expand All @@ -34,6 +35,7 @@ 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)
Expand All @@ -60,3 +62,25 @@ 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))
}
}

0 comments on commit 949ac8a

Please sign in to comment.