Skip to content

Commit

Permalink
Add receiver phone and email to the payment.ReceiverWallet.Receiver b…
Browse files Browse the repository at this point in the history
…ody.
  • Loading branch information
marcelosalloum committed Dec 9, 2024
1 parent c2bcc50 commit eb34fe4
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 10 deletions.
9 changes: 6 additions & 3 deletions internal/data/payments.go
Original file line number Diff line number Diff line change
Expand Up @@ -375,15 +375,18 @@ const getReadyPaymentsBaseQuery = `
a.issuer as "asset.issuer",
rw.id as "receiver_wallet.id",
rw.receiver_id as "receiver_wallet.receiver.id",
COALESCE(r.phone_number, '') as "receiver_wallet.receiver.phone_number",
COALESCE(r.email, '') as "receiver_wallet.receiver.email",
COALESCE(rw.stellar_address, '') as "receiver_wallet.stellar_address",
COALESCE(rw.stellar_memo, '') as "receiver_wallet.stellar_memo",
COALESCE(rw.stellar_memo_type, '') as "receiver_wallet.stellar_memo_type",
rw.status as "receiver_wallet.status"
FROM
payments p
JOIN assets a on p.asset_id = a.id
JOIN receiver_wallets rw on p.receiver_wallet_id = rw.id
JOIN disbursements d on p.disbursement_id = d.id
JOIN assets a ON p.asset_id = a.id
JOIN disbursements d ON p.disbursement_id = d.id
JOIN receiver_wallets rw ON p.receiver_wallet_id = rw.id
JOIN receivers r ON rw.receiver_id = r.id
WHERE
p.status = $1 -- 'READY'::payment_status
AND rw.status = $2 -- 'REGISTERED'::receiver_wallet_status
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,13 +197,17 @@ func (c *CirclePaymentDispatcher) ensureRecipientIsReady(ctx context.Context, re
}

// NULL, PENDING, INACTIVE (with renovated idempotency_key) or FAILED (with renovated idempotency_key) -> (re)submit the recipient creation request
nickname := receiverWallet.ID
if receiverWallet.Receiver.PhoneNumber != "" {
nickname = receiverWallet.Receiver.PhoneNumber
}
recipient, err := c.circleService.PostRecipient(ctx, circle.RecipientRequest{
IdempotencyKey: dataRecipient.IdempotencyKey,
Address: receiverWallet.StellarAddress,
Chain: circle.StellarChainCode,
Metadata: circle.RecipientMetadata{
Nickname: receiverWallet.ID, // TODO: replace with phone number if available
// TODO: add email
Nickname: nickname,
Email: receiverWallet.Receiver.Email,
},
})
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ func Test_CirclePaymentDispatcher_ensureRecipientIsReady_success(t *testing.T) {
assert.Equal(t, recipientInsertTemplate.IdempotencyKey, recipientRequest.IdempotencyKey)
assert.Equal(t, receiverWallet.StellarAddress, recipientRequest.Address)
assert.Equal(t, circle.StellarChainCode, recipientRequest.Chain)
assert.Equal(t, receiverWallet.ID, recipientRequest.Metadata.Nickname)
assert.Equal(t, receiverWallet.Receiver.PhoneNumber, recipientRequest.Metadata.Nickname)
assert.Equal(t, receiverWallet.Receiver.Email, recipientRequest.Metadata.Email)
}).
Return(&circle.Recipient{ID: "new-circle-recipient-id", Status: "active"}, nil).
Once()
Expand All @@ -116,7 +117,8 @@ func Test_CirclePaymentDispatcher_ensureRecipientIsReady_success(t *testing.T) {
assert.NotEqual(t, recipientInsertTemplate.IdempotencyKey, recipientRequest.IdempotencyKey)
assert.Equal(t, receiverWallet.StellarAddress, recipientRequest.Address)
assert.Equal(t, circle.StellarChainCode, recipientRequest.Chain)
assert.Equal(t, receiverWallet.ID, recipientRequest.Metadata.Nickname)
assert.Equal(t, receiverWallet.Receiver.PhoneNumber, recipientRequest.Metadata.Nickname)
assert.Equal(t, receiverWallet.Receiver.Email, recipientRequest.Metadata.Email)
}).
Return(&circle.Recipient{ID: "new-circle-recipient-id", Status: "active"}, nil).
Once()
Expand Down Expand Up @@ -150,7 +152,8 @@ func Test_CirclePaymentDispatcher_ensureRecipientIsReady_success(t *testing.T) {
assert.NotEqual(t, recipientInsertTemplate.IdempotencyKey, recipientRequest.IdempotencyKey)
assert.Equal(t, receiverWallet.StellarAddress, recipientRequest.Address)
assert.Equal(t, circle.StellarChainCode, recipientRequest.Chain)
assert.Equal(t, receiverWallet.ID, recipientRequest.Metadata.Nickname)
assert.Equal(t, receiverWallet.Receiver.PhoneNumber, recipientRequest.Metadata.Nickname)
assert.Equal(t, receiverWallet.Receiver.Email, recipientRequest.Metadata.Email)
}).
Return(&circle.Recipient{ID: "new-circle-recipient-id", Status: "active"}, nil).
Once()
Expand Down Expand Up @@ -236,7 +239,8 @@ func Test_CirclePaymentDispatcher_ensureRecipientIsReady_failure(t *testing.T) {
assert.Equal(t, recipientInsertTemplate.IdempotencyKey, recipientRequest.IdempotencyKey)
assert.Equal(t, receiverWallet.StellarAddress, recipientRequest.Address)
assert.Equal(t, circle.StellarChainCode, recipientRequest.Chain)
assert.Equal(t, receiverWallet.ID, recipientRequest.Metadata.Nickname)
assert.Equal(t, receiverWallet.Receiver.PhoneNumber, recipientRequest.Metadata.Nickname)
assert.Equal(t, receiverWallet.Receiver.Email, recipientRequest.Metadata.Email)
}).
Return(nil, errors.New("got 400 from vendor's API")).
Once()
Expand Down Expand Up @@ -293,7 +297,7 @@ func Test_CirclePaymentDispatcher_DispatchPayments(t *testing.T) {
require.NoError(t, err)

circleWalletID := "22322112"
circlePayoutID := uuid.NewString()
circlePayoutID := "dce3a913-9043-4d20-ba6c-fe27f630f2a0"

tenantID := "tenant-id"

Expand Down

0 comments on commit eb34fe4

Please sign in to comment.