getsafepay / safepay-node

Safepay node.js client
MIT License
6 stars 3 forks source link

no way to add customers? #21

Open abdullahmoh21 opened 2 weeks ago

abdullahmoh21 commented 2 weeks ago

I have a few questions about current behavior of the SDK:

  1. Is there any way to add user data to my payment so that user does not have to enter details every time at checkout(other than user creating a Safepay account)? For example, if i create a customer using the following endpoint: POST https://dev.api.getsafepay.com/user/customers/v1 , is there any way to add said customer when i create a payment using:

    ({ token } = await safepay.payments.create({
        amount: booking.amount,
        currency: booking.paymentCurrency,
    }));    
  2. I do not require user's physical address. is there way i can generate a checkout link that does not ask user for this input or this required by Safepay?

  3. Is there any specific endpoint i can call to get the status of a transaction using the above tracker token? or is a webhook the only way to get a pending transactions status updates?

  4. Is there a way to create refunds using the SDK. or does one have to call the refund endpoint for that.

  5. while attempting to call the refund endpoint. I keep getting a HTTP 500 error. Since this is an error on your end how should i navigate around this? or do you send 500 codes for bad requests as well? here is my relevant node code:

    var options = {
        method: 'post',
        maxBodyLength: Infinity,
        url: `https://sandbox.api.getsafepay.com/order/payments/v3/${payment.tracker}/refund`,
        headers: {
            'X-SFPY-MERCHANT-SECRET': process.env.SAFEPAY_SECRET_KEY,
        },
        data : {
            "currency": payment.currency,
            "amount": payment.amount,
        }
    };
    let response;
    try {
        response = await axios(options)
        conole.log(`Safepay Response: ${response}`)
    } catch (error) {
        console.error(`Error refunding payment: ${error}`);
        console.log(`Safepay Response: ${JSON.stringify(response, null, 2)} `)
        return res.sendStatus(500);
    }

    package: "@sfpy/node-sdk": "^3.0.1" When i send above response here are my debug logs:

    Attempting to refund payment: track_7d990a9d-7dd6-484a-b91d-95e93503737f
    Error refunding payment: Error: Request failed with status code 500
    Safepay Response: undefined 

    Please let me know why I am receiving a 500 code and if there is anything i can do to fix it.

Thank you in advance!

fatimaaurangzeb0640 commented 1 week ago

Hello, thank you for your questions.

  1. yep there's a way to do that but as of now it is not supported in the sdk so you're gonna have to called this endpoint: https://sandbox.api.getsafepay.com/order/payments/v3/ and send the customer id in the body like this after creating the customer

{ user: "cus_99642a9a-704e-4fff-bb49-067a6949ba11"}

  1. it is required by safepay so the user will have to enter the address every time they make a payment by entering their card details

  2. there is an endpoint to do that but it is not supported in the sdk so you will have to call the endpoint https://sandbox.api.getsafepay.com/api/v1/payments/track_27ca0d9e-80a4-46cc-abc0-fd095e3d09bc to fetch the payment details

  3. it is not supported in the sdk but you can call this endpoint to refund a payment https://sandbox.api.getsafepay.com/payments/v3/track_27ca0d9e-80a4-46cc-abc0-fd095e3d09bc/refund or you can also go to your merchant dashboard to do that

  4. what is the status of your tracker at this point?

abdullahmoh21 commented 1 week ago

thank you for your response. I have been having some issues with the refund endpoint and the "get payment status" endpoint. when i call the endpoint GET https://sandbox.api.getsafepay.com/api/v1/payments/${tracker}i simply get served the safepay.com homepage (I am assuming this is a catch all for requests). here is how i am calling it:

    const options = {
        method: 'get',
        maxBodyLength: Infinity,
        url: `https://sandbox.api.getsafepay.com/api/v3/payments/${tracker}`,
        headers: {
            'X-SFPY-MERCHANT-SECRET': process.env.SAFEPAY_SECRET_KEY,
        },
    }
    try {
        const response = await axios(options);
        logger.info(`Safepay Response: ${JSON.stringify(response.data, null, 2)}`);
        return res.status(200).json(response.data);
    } catch (error) {
        logger.error(`Error getting payment status: ${error}`);
        return res.status(500).json({'message': 'No response was returned'}); // Internal Server Error
    }

why is this happening? is the endpoint url incorrect? Also i assumed the method would be GET, is this the case? The api docs are extremely lacking in this regard. are the v1 api docs somewhere else? because there is no mention of these endpoints here

(in response to 5.) : my payment is completed when i am calling the refund endpoint. do you see any issue with how i am calling the refund endpoint(code above)?

(in response to 1. ) : would it be possible to create the payment using the SDK's await safepay.payments.create method and then add customer data later using the endpoint you mentioned? or if i want to add customer data will i have to do everything via endpoint?

here is the html i receive when trying to access a payment details: Screenshot 2024-06-26 at 3 19 01 AM