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

Bexio fixes #1119

Merged
merged 19 commits into from
Jan 16, 2024
Merged

Bexio fixes #1119

merged 19 commits into from
Jan 16, 2024

Conversation

elias-summermatter
Copy link
Member

No description provided.

Copy link

github-actions bot commented Dec 6, 2023

@elias-summermatter elias-summermatter marked this pull request as ready for review December 6, 2023 16:13
} from './bexio-errors'
import {addToStringReplaceMap, mapBexioStatusToPaymentStatus, searchForContact} from './bexio-utils'
import fetch from 'node-fetch'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this imported here? I can't see it used in your changes

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see it on line 150.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it was added by me, but starting with node 18 there's no longer need to import fetch from node-fetch (it's included). But I think it's still ok, it can still be imported as a "fallback" if older version of node is used

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WePublish is no node 16 not 18...

paymentData: JSON.stringify(bexioResponse.data),
customerID: bexioResponse.data.contact_id ? bexioResponse.data.contact_id.toString() : ''
paymentID: payment.id,
paymentData: JSON.stringify(bexioResponse),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are you sure that you don't want to dive into data, just return response?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's right without data. Once you use json() you get full response and that is:
image

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good

@antkiewiczk
Copy link
Contributor

Also please fix tests for bexio

@@ -40,11 +40,18 @@ class NoSubscriptionIdInInvoice extends Error {
}
}

class PaymentNotFound extends Error {
constructor(message = 'While checking intent, payment not found!') {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at the error class name its message should not determine the reason why it's thrown.

Copy link
Member Author

@elias-summermatter elias-summermatter Dec 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is your proposal here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tomaszdurka Can you give me more datails here?

} from './bexio-errors'
import {addToStringReplaceMap, mapBexioStatusToPaymentStatus, searchForContact} from './bexio-utils'
import fetch from 'node-fetch'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see it on line 150.

@@ -232,7 +249,7 @@ export class BexioPaymentProvider extends BasePaymentProvider {

return {
intentID: newInvoice.id.toString(),
intentSecret: '',
intentSecret: successURL,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Questions @elias-summermatter:

  1. Why are we storing things like successUrl in the intentSecret?
  2. Btw I understand this is something used by frontend website, right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's have a call about that. It's faster that way, just call me when you got time.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we have a summary here? I guess it's for the redirect on the frontend?

Copy link
Member Author

@elias-summermatter elias-summermatter Dec 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. Intent is where the frontend is redirected to do the payment (for payrexx and stripe checkout). In case of Bexio the invoice is already created, so we just redirect the UI to the success url because in case of Bexio there is no extra action required on a bexio page. It allows bexio integration in the fronted without any significant changes.

const bexioInvoice: InvoicesStatic.InvoiceCreate = {
title: isRenewal ? this.invoiceTitleRenewalMembership : this.invoiceTitleNewMembership,
contact_id: contact.id,
user_id: this.userId,
mwst_type: 0,
mwst_is_net: false,
// Override for wrong library implementation!
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We hardly want to use ts-ignore so let's change add special type like:

type InvoiceCreate = Omit<InvoicesStatic.InvoiceCreate, 'api_reference'> & { "api_reference"?: string | null };

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made a pr to the bexio library to fix that, as soon as the fix is deployed we can remove this hack but it was needed to be able to deploy and test it on hauptstadt site. Was never intended to stay in there:
mathewmeconry/bexio#61

@@ -122,7 +124,7 @@ export class BexioPaymentProvider extends BasePaymentProvider {
* @returns {Promise<void>} Resolves when the remote invoice is successfully created.
*/
async createRemoteInvoice(props: CreateRemoteInvoiceProps) {
await this.bexioCreate(props.invoice.id, true)
await this.bexioCreate('', props.invoice.id, true)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's make successUrl optional and not pass it here.

paymentData: JSON.stringify(bexioResponse.data),
customerID: bexioResponse.data.contact_id ? bexioResponse.data.contact_id.toString() : ''
paymentID: payment.id,
paymentData: JSON.stringify(bexioResponse),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's right without data. Once you use json() you get full response and that is:
image

.env Outdated
@@ -61,10 +61,11 @@ ENABLE_ANONYMOUS_COMMENTS=false

MAX_AUTO_RENEW_SUBSCRIPTION_BATCH=false

BEXIO_API_KEY=secret
BEXIO_USER_ID=1
BEXIO_API_KEY=eyJraWQiOiI2ZGM2YmJlOC1iMjZjLTExZTgtOGUwZC0wMjQyYWMxMTAwMDIiLCJhbGciOiJSUzI1NiJ9.eyJzdWIiOiJtYXRoaWFzLnN0cmVpdEBoYXVwdHN0YWR0LmJlIiwibG9naW5faWQiOiI5ZmNlMTNkOS1hN2ZhLTRiZmItOWFhNy03ZmI0NjY1ZTMxOTMiLCJjb21wYW55X2lkIjoiam41ZXlmejF2dmV1IiwidXNlcl9pZCI6MzE0MDMzLCJhenAiOiJldmVybGFzdC10b2tlbi1vZmZpY2UtY2xpZW50Iiwic2NvcGUiOiJvcGVuaWQgcHJvZmlsZSBlbWFpbCBhbGwgdGVjaG5pY2FsIiwiaXNzIjoiaHR0cHM6XC9cL2lkcC5iZXhpby5jb20iLCJleHAiOjMyNzg2NjQ4NDksImlhdCI6MTcwMTg2NDg0OSwiY29tcGFueV91c2VyX2lkIjoyLCJqdGkiOiI0OGM5ODg1ZS1hOTI2LTRlZTQtOTU0Zi02YTI1NGFiMDIwMGEifQ.ByaZmYhguwjFmzvkAXABwr4sFzMEPKID4clV7ygdpRNKbQ8FkoGmk0XWkyjW6q2pWOAeOQcwmw5p3uxkUtqMN8QsycW2Q4kFSlRxAu4SH69OqqypcaSmeBCI4UmewYjZykBEBpgBy0Ex9n9hkz9ty96Me-eRr4bVDS1CApEX7PVixLOMWkbgEySAA2S_JP9ZHdhzRqBfsLoIOK_DzZd-w8tGi29wPgjl4oTDmt_iokgg1lownQ0_UqhtvRLvGp_hJHMqiEpUryDhBLnHDWIPPofJf442ZeI1eQdAcN2vzdGAUxWpkztLfe1Q1_3WOBQvOs87pLGwprbcDSjbGnl1LmnPuj8tVRnBq4LtjMk1oC7v3gXDIjtyFNyPKNOFOrPDKJ-CIg25NwoGeZukQ4m2SrsSkAuGK2avuDZoU6Z9Krv9KvAw2JKJRfdvD2ICseIyaudgC2hRDk493G_auq2tM4nsqVWi_79owd2MhljqZazLGbBZAtS42soVTy4sUyy36mLbSTy5YXFVlXZysCLZEPa7ItNv3pGd4nQtww133GkOzgzBQzodW2EoWoxUnTssBk6L9c4f4wOiAOVGVH_1rAu-XloYHkvhlp--qO1nLXqjFUuS1Zgh8Vuof2L5LI1tKPR9T8SiqbvrNTlZAjnyOizK0R0c68JuJH1KulvD_t4
Copy link
Collaborator

@Itrulia Itrulia Dec 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this intended?

If you want to override specific env variables then you can create a .env.local

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ou fuck... I revoked the key.... Thanks for noticing...

Copy link
Collaborator

@Itrulia Itrulia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

in case this was forgotten

@elias-summermatter
Copy link
Member Author

@antkiewiczk & @tomaszdurka can you review it again that we can merge it if ok. Thanks :-)

Copy link

codecov bot commented Jan 15, 2024

Codecov Report

Attention: 1 lines in your changes are missing coverage. Please review.

Comparison is base (99d94f9) 40.67% compared to head (d334c86) 41.03%.
Report is 6 commits behind head on master.

Files Patch % Lines
...b/payment-provider/bexio/bexio-payment-provider.ts 90.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1119      +/-   ##
==========================================
+ Coverage   40.67%   41.03%   +0.36%     
==========================================
  Files         296      296              
  Lines        7548     7554       +6     
  Branches     1561     1561              
==========================================
+ Hits         3070     3100      +30     
+ Misses       4312     4283      -29     
- Partials      166      171       +5     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

antkiewiczk
antkiewiczk previously approved these changes Jan 16, 2024
}
})

jest.mock('node-fetch', () =>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Itrulia
Itrulia previously approved these changes Jan 16, 2024
@elias-summermatter
Copy link
Member Author

@antkiewiczk improved test coverage can you also review it :-)

@elias-summermatter elias-summermatter merged commit df0e4f1 into master Jan 16, 2024
11 checks passed
@elias-summermatter elias-summermatter deleted the b/fix-bexio-payment-adapter branch January 16, 2024 15:50
@tomaszdurka tomaszdurka mentioned this pull request Jan 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants