diff --git a/internal/data/payments.go b/internal/data/payments.go index ac02028b..d4362a4e 100644 --- a/internal/data/payments.go +++ b/internal/data/payments.go @@ -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 diff --git a/internal/services/paymentdispatchers/circle_payment_dispatcher.go b/internal/services/paymentdispatchers/circle_payment_dispatcher.go index 024478ed..f75e41be 100644 --- a/internal/services/paymentdispatchers/circle_payment_dispatcher.go +++ b/internal/services/paymentdispatchers/circle_payment_dispatcher.go @@ -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 { diff --git a/internal/services/paymentdispatchers/circle_payment_dispatcher_test.go b/internal/services/paymentdispatchers/circle_payment_dispatcher_test.go index b5278d64..ad3679d4 100644 --- a/internal/services/paymentdispatchers/circle_payment_dispatcher_test.go +++ b/internal/services/paymentdispatchers/circle_payment_dispatcher_test.go @@ -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() @@ -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() @@ -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() @@ -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() @@ -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"