vtex-apps / payment-provider-example

A reference app implementing a Payment-Provider protocol
13 stars 17 forks source link

How to make a http call to payment service from connector.ts? #28

Open bhuvana-lingam opened 2 years ago

bhuvana-lingam commented 2 years ago

What are you trying to accomplish? Please describe. We are trying integrate paypal payflow pro with vtex

What have you tried so far? Tried to make an external api call in connector.ts file using this.http.post(). Not able to access http object in the context. image Additional info Add extra content here (code samples, screenshots,...)

Can you pls let me know how to make http calls?

Account Workspace
your account your workspace
rafaelrcamargo commented 2 years ago

Hey @bhuvana-lingam!

Maybe i'm here too late, but i ran through the same problem some days ago. I even tried axios with the correlated polices, but meh, nothing better than a 403.

Then the change we had to make was to change a bit the approach and implement some clients, this step is really close to the node service, but as i was able to search i found nothing from VTEX related to doing this with the payment-provider, only a public repo from some years ago, but was enougth to found the way.

We first create a client and a index.ts inside de clients/ folder, using the same template from a common node service, than we implement this in the index.ts of the project, in a non-clear way, but having in mind that this service is extended from the common one, makes sense.

image

Here we create our client extending the @vtex/api ExternalClient


image

And finally implement it here, with the Payment Provider Service

I hope that helps more people struggling with this!

Lohins commented 1 year ago

Hi, @rafaelrcamargo thanks for your answer, I still got some questions if you mind.

  1. do you make external calls to your own payment service from the class inherited from ExternalClient.
  2. if the above one is true, how do you use those client functions (like createPayment) in connector?
  3. I don't understand why clients are plural, do you have multiple client here? I thought there was only one client which makes external calls.

Appreciate if you can answer those. Thanks!