mobilpay / Node.js

Proof of concept - mobilPay integration in Node.js
8 stars 4 forks source link

Not very useful - any hope for a complete example ? #3

Closed bogdan-calapod closed 5 years ago

bogdan-calapod commented 5 years ago

The provided example is not very useful:

bogdan-calapod commented 5 years ago

I've found this library and tried to test it in the sandbox. When I run the code and go to the redirect URL to netopia, I get this message:

IDS_Model_Purchase_Abstract_DB_INSERT_FAILED

Any idea what might cause this ? This is running in the sandbox environment (http://sandboxsecure.mobilpay.ro/). Also a bit weird is that I am being redirected to a http://, not a https:// page.

I could make a PR explaining how to use the library from robi-richter in the Readme, at least it would help developers trying to integrate with mobilPay.

fakeplayerr commented 5 years ago

Hello Bogdan,

Example:

// make the request
getRequest("orderId")

// decode the response
decodeResponse(data).then(function (resolve, reject) {
  // handle response
}).catch(function (resolve, reject) {
  // handle errors
})

All the details needed are shown in the JSON object. Note that you have to use the crt file directly and not extract the public certificate like it says in that library

You could break down a little the getPayment function to take another parameter, the JSON object, and then send it to it after you filled that in.

// in the getRequest function
getPayment(orderId, 1, 'RON', jsonData)

P.S. i tested the module and it works for me. you may be sending something wrong, or not sending something. Check again and let me know if that helped.

bogdan-calapod commented 5 years ago

Hello @fakeplayerr and thanks for the tips

I have managed to link the request form and to get to the point to display the payment form to the user. I am having a bit of trouble with handling the /confirm url response. I guess this is why the transactions don't show up in the sandbox admin pane.

My route handler looks like this:

app.post('/confirm', async (req, res) => {
  try {
    const resp = await decodeResponse({
      env_key: req.body.env_key,
      data: req.body.data
    })
    res.send(resp)
  } catch (e) {
    console.error('Error decoding response')
    console.error(e.message)
    console.error(e)
    res.status(500).send()
  }
})

And the error it throws is this:

Error decoding response
error:0407109F:rsa routines:RSA_padding_check_PKCS1_type_2:pkcs decoding error
Error: error:0407109F:rsa routines:RSA_padding_check_PKCS1_type_2:pkcs decoding error
    at Object.privateDecrypt (internal/crypto/cipher.js:53:12)

The keys that I am using are the public and private keys that I got from the production admin pane for the merchant account that I have synchronized with the sandbox pane (I couldn't find an option to download the certificates in the sandbox admin pane) - I think this might be the issue ?

I've obtained a .pem from the .cer by running the following command:

openssl x509 -pubkey -noout -in PUBLIC_CERTIFICATE_FILE.cer > PUBLIC_KEY.pem

I expect that I have missed some small thing that is causing the error. What do you think ?

Also, would it be okay if I made a PR with a more fleshed-out example with express and a basic form for processing payments ?

fakeplayerr commented 5 years ago

I tested your function. It works for me

The problem may be that you are using the wrong private key.

if you use sanboxsecure.mobilpay.ro you need the sandbox private key if you use secure.mobilpay.ro you need the admin private key

the same is for the public key.

As I said in the previous response. You don't need to extract the public key from the .cer file. You can use it directly and it should work

Let me know if it worked

bogdan-calapod commented 5 years ago

Hello,

Indeed the problem was with the private key. I've synced the account from the production server with the sandbox server and the sandbox option appeared, allowing me to download the private key.

Thank you for your help! I'll try to make a PR with a complete Express flow example these days.

DragoshDX commented 2 years ago

Hello @bogdan-calapod, did you manage to publish a better example?