Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(payments): add original reference in psp payment #1722

Merged
merged 3 commits into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -100,15 +100,15 @@ func translatePayment(from client.Payment) (*models.PSPPayment, error) {
}

payment := models.PSPPayment{
OriginalReference: from.PaymentID,
Reference: from.PaymentID,
CreatedAt: from.ProcessedTimestamp,
Type: paymentType,
Amount: amount,
Asset: currency.FormatAsset(supportedCurrenciesWithDecimal, from.Transfer.Amount.Currency),
Scheme: models.PAYMENT_SCHEME_OTHER,
Status: matchPaymentStatus(from.Status),
Raw: raw,
ParentReference: from.PaymentID,
Reference: from.PaymentID,
CreatedAt: from.ProcessedTimestamp,
Type: paymentType,
Amount: amount,
Asset: currency.FormatAsset(supportedCurrenciesWithDecimal, from.Transfer.Amount.Currency),
Scheme: models.PAYMENT_SCHEME_OTHER,
Status: matchPaymentStatus(from.Status),
Raw: raw,
}

if from.DebtorInformation.AccountID != "" {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,15 @@ func transactionToPayment(transaction client.Transaction) (*models.PSPPayment, e
paymentType := matchTransactionType(transaction.Type)

payment := &models.PSPPayment{
OriginalReference: transaction.ID,
Reference: transaction.ID,
CreatedAt: transaction.CreatedAt,
Type: paymentType,
Amount: amount,
Asset: currency.FormatAsset(supportedCurrenciesWithDecimal, transaction.Currency),
Scheme: models.PAYMENT_SCHEME_OTHER,
Status: matchTransactionStatus(transaction.Status),
Raw: raw,
ParentReference: transaction.ID,
paul-nicolas marked this conversation as resolved.
Show resolved Hide resolved
Reference: transaction.ID,
CreatedAt: transaction.CreatedAt,
Type: paymentType,
Amount: amount,
Asset: currency.FormatAsset(supportedCurrenciesWithDecimal, transaction.Currency),
Scheme: models.PAYMENT_SCHEME_OTHER,
Status: matchTransactionStatus(transaction.Status),
Raw: raw,
}

switch paymentType {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,15 +115,15 @@ func transactionToPayment(from client.Payment) (*models.PSPPayment, error) {
}

payment := models.PSPPayment{
OriginalReference: from.Id,
Reference: from.Id,
CreatedAt: time.Unix(from.CreationDate, 0),
Type: paymentType,
Amount: &amount,
Asset: currency.FormatAsset(supportedCurrenciesWithDecimal, from.DebitedFunds.Currency),
Scheme: models.PAYMENT_SCHEME_OTHER,
Status: paymentStatus,
Raw: raw,
ParentReference: from.Id,
Reference: from.Id,
CreatedAt: time.Unix(from.CreationDate, 0),
Type: paymentType,
Amount: &amount,
Asset: currency.FormatAsset(supportedCurrenciesWithDecimal, from.DebitedFunds.Currency),
Scheme: models.PAYMENT_SCHEME_OTHER,
Status: paymentStatus,
Raw: raw,
}

if from.DebitedWalletID != "" {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,15 +183,15 @@ func (p Plugin) translateTransfer(ctx context.Context, req webhookTranslateReque
}

payment := models.PSPPayment{
OriginalReference: transfer.ID,
Reference: transfer.ID,
CreatedAt: time.Unix(transfer.CreationDate, 0),
Type: models.PAYMENT_TYPE_TRANSFER,
Amount: &amount,
Asset: currency.FormatAsset(supportedCurrenciesWithDecimal, transfer.DebitedFunds.Currency),
Scheme: models.PAYMENT_SCHEME_OTHER,
Status: paymentStatus,
Raw: raw,
ParentReference: transfer.ID,
Reference: transfer.ID,
CreatedAt: time.Unix(transfer.CreationDate, 0),
Type: models.PAYMENT_TYPE_TRANSFER,
Amount: &amount,
Asset: currency.FormatAsset(supportedCurrenciesWithDecimal, transfer.DebitedFunds.Currency),
Scheme: models.PAYMENT_SCHEME_OTHER,
Status: paymentStatus,
Raw: raw,
}

if transfer.DebitedWalletID != "" {
Expand Down Expand Up @@ -228,15 +228,15 @@ func (p Plugin) translatePayout(ctx context.Context, req webhookTranslateRequest
}

payment := models.PSPPayment{
OriginalReference: payout.ID,
Reference: payout.ID,
CreatedAt: time.Unix(payout.CreationDate, 0),
Type: models.PAYMENT_TYPE_PAYOUT,
Amount: &amount,
Asset: currency.FormatAsset(supportedCurrenciesWithDecimal, payout.DebitedFunds.Currency),
Scheme: models.PAYMENT_SCHEME_OTHER,
Status: paymentStatus,
Raw: raw,
ParentReference: payout.ID,
Reference: payout.ID,
CreatedAt: time.Unix(payout.CreationDate, 0),
Type: models.PAYMENT_TYPE_PAYOUT,
Amount: &amount,
Asset: currency.FormatAsset(supportedCurrenciesWithDecimal, payout.DebitedFunds.Currency),
Scheme: models.PAYMENT_SCHEME_OTHER,
Status: paymentStatus,
Raw: raw,
}

if payout.DebitedWalletID != "" {
Expand Down Expand Up @@ -269,15 +269,15 @@ func (p Plugin) translatePayin(ctx context.Context, req webhookTranslateRequest)
}

payment := models.PSPPayment{
OriginalReference: payin.ID,
Reference: payin.ID,
CreatedAt: time.Unix(payin.CreationDate, 0),
Type: models.PAYMENT_TYPE_PAYIN,
Amount: &amount,
Asset: currency.FormatAsset(supportedCurrenciesWithDecimal, payin.DebitedFunds.Currency),
Scheme: models.PAYMENT_SCHEME_OTHER,
Status: paymentStatus,
Raw: raw,
ParentReference: payin.ID,
Reference: payin.ID,
CreatedAt: time.Unix(payin.CreationDate, 0),
Type: models.PAYMENT_TYPE_PAYIN,
Amount: &amount,
Asset: currency.FormatAsset(supportedCurrenciesWithDecimal, payin.DebitedFunds.Currency),
Scheme: models.PAYMENT_SCHEME_OTHER,
Status: paymentStatus,
Raw: raw,
}

if payin.CreditedWalletID != "" {
Expand Down Expand Up @@ -310,15 +310,15 @@ func (p Plugin) translateRefund(ctx context.Context, req webhookTranslateRequest
}

payment := models.PSPPayment{
OriginalReference: refund.InitialTransactionID,
Reference: refund.ID,
CreatedAt: time.Unix(refund.CreationDate, 0),
Type: paymentType,
Amount: &amountRefunded,
Asset: currency.FormatAsset(supportedCurrenciesWithDecimal, refund.DebitedFunds.Currency),
Scheme: models.PAYMENT_SCHEME_OTHER,
Status: models.PAYMENT_STATUS_REFUNDED,
Raw: raw,
ParentReference: refund.InitialTransactionID,
Reference: refund.ID,
CreatedAt: time.Unix(refund.CreationDate, 0),
Type: paymentType,
Amount: &amountRefunded,
Asset: currency.FormatAsset(supportedCurrenciesWithDecimal, refund.DebitedFunds.Currency),
Scheme: models.PAYMENT_SCHEME_OTHER,
Status: models.PAYMENT_STATUS_REFUNDED,
Raw: raw,
}

return models.WebhookResponse{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,15 +120,15 @@ func transactionToPayment(transaction client.Transaction, from models.PSPAccount
}

payment := &models.PSPPayment{
OriginalReference: transaction.ID,
Reference: transaction.ID,
CreatedAt: createdAt,
Type: paymentType,
Amount: amount,
Asset: currency.FormatAsset(supportedCurrenciesWithDecimal, transaction.Account.Currency),
Scheme: models.PAYMENT_SCHEME_OTHER,
Status: models.PAYMENT_STATUS_SUCCEEDED,
Raw: raw,
ParentReference: transaction.ID,
Reference: transaction.ID,
CreatedAt: createdAt,
Type: paymentType,
Amount: amount,
Asset: currency.FormatAsset(supportedCurrenciesWithDecimal, transaction.Account.Currency),
Scheme: models.PAYMENT_SCHEME_OTHER,
Status: models.PAYMENT_STATUS_SUCCEEDED,
Raw: raw,
}

switch paymentType {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,16 +128,16 @@ func transactionToPayment(transaction *client.Transaction) (*models.PSPPayment,
}

payment := models.PSPPayment{
OriginalReference: transaction.ID,
Reference: transaction.ID,
CreatedAt: createdAt,
Type: paymentType,
Amount: amount,
Asset: currency.FormatAsset(supportedCurrenciesWithDecimal, transaction.Attributes.Currency),
Scheme: models.PAYMENT_SCHEME_OTHER,
Status: models.PAYMENT_STATUS_SUCCEEDED,
Metadata: map[string]string{},
Raw: rawData,
ParentReference: transaction.ID,
Reference: transaction.ID,
CreatedAt: createdAt,
Type: paymentType,
Amount: amount,
Asset: currency.FormatAsset(supportedCurrenciesWithDecimal, transaction.Attributes.Currency),
Scheme: models.PAYMENT_SCHEME_OTHER,
Status: models.PAYMENT_STATUS_SUCCEEDED,
Metadata: map[string]string{},
Raw: rawData,
}

switch paymentType {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,15 @@ func fromTransferToPayment(from client.Transfer) (*models.PSPPayment, error) {
}

p := models.PSPPayment{
OriginalReference: fmt.Sprintf("%d", from.ID),
Reference: fmt.Sprintf("%d", from.ID),
CreatedAt: from.CreatedAt,
Type: models.PAYMENT_TYPE_TRANSFER,
Amount: amount,
Asset: currency.FormatAsset(supportedCurrenciesWithDecimal, from.TargetCurrency),
Scheme: models.PAYMENT_SCHEME_OTHER,
Status: matchTransferStatus(from.Status),
Raw: raw,
ParentReference: fmt.Sprintf("%d", from.ID),
Reference: fmt.Sprintf("%d", from.ID),
CreatedAt: from.CreatedAt,
Type: models.PAYMENT_TYPE_TRANSFER,
Amount: amount,
Asset: currency.FormatAsset(supportedCurrenciesWithDecimal, from.TargetCurrency),
Scheme: models.PAYMENT_SCHEME_OTHER,
Status: matchTransferStatus(from.Status),
Raw: raw,
}

if from.SourceBalanceID != 0 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,15 +117,15 @@ func (p Plugin) translateBalanceUpdateWebhook(ctx context.Context, req models.Tr
}

payment := models.PSPPayment{
Reference: update.Data.TransferReference,
OriginalReference: update.Data.TransferReference,
CreatedAt: occuredAt,
Type: paymentType,
Amount: amount,
Asset: currency.FormatAsset(supportedCurrenciesWithDecimal, update.Data.Currency),
Scheme: models.PAYMENT_SCHEME_OTHER,
Status: models.PAYMENT_STATUS_SUCCEEDED,
Raw: raw,
Reference: update.Data.TransferReference,
ParentReference: update.Data.TransferReference,
CreatedAt: occuredAt,
Type: paymentType,
Amount: amount,
Asset: currency.FormatAsset(supportedCurrenciesWithDecimal, update.Data.Currency),
Scheme: models.PAYMENT_SCHEME_OTHER,
Status: models.PAYMENT_STATUS_SUCCEEDED,
Raw: raw,
}

switch paymentType {
Expand Down
Loading