3d-securenetbanx-apipaysafe

When I try to send a request to Paysafe, I keep getting the following response form the API


Here is my code that I am using to make my request.

   {
    "total_amount": "1000",
    "currency_code": "USD",
    "merchant_ref_num": "12345678",
    "customer_notification_email": "test@test.com",
    "profile": {
        "firstName": "Test",
        "lastName": "Sample",
        "merchantCustomerId": "12345678"
    },
    "billingDetails": {
        "city": "Montreal",
        "country": "CA",
        "street": "123 Main Apt 200",
        "zip": "H1H1H1",
        "state": "QC",
        "phone": "555-555-5555"
    },
    "extendedOptions": [
        {
            "key": "authType",
            "value": "auth"
        },
        {
            "key": "orderTimeout",
            "value": 2592000
        },
        {
            "key": "suppressCustomerEmail",
            "value": true
        },
      {
            "key": "silentPost",
            "value": false
        }
    ],
    "callback": [
        {
            "format": "get",
            "rel": "on_success",
            "uri": "https://secure4137.hostgator.com/~cmedei/optimal/callbacks/callback.php",
            "returnKeys": [
                "id",
                "profile.paymentToken",
                "profile.id",
                "transaction.errorCode",
                "transaction.errorMessage",
                "transaction.confirmationNumber",
                "transaction.amount",
                "transaction.authType",
                "transaction.status",
                "transaction.currencyCode",
                "transaction.merchantRefNum",
                "transaction.card.brand",
                "transaction.card.country",
                "transaction.card.expiry",
                "transaction.card.lastDigits",
                "transaction.card.threeDEnrolment",
                "transaction.card.threeDResult",
                "transaction.card.type",
                "transaction.paymentType",
                "transaction.prepaidcard.lastDigits"
            ],
            "retries": 3,
            "synchronous": true
        },
        {
            "format": "get",
            "rel": "on_decline",
            "uri": "https://secure4137.hostgator.com/~cmedei/optimal/callbacks/callback.php",
            "returnKeys": [
                "id",
                "profile.paymentToken",
                "profile.id",
                "transaction.errorCode",
                "transaction.errorMessage",
                "transaction.confirmationNumber",
               "transaction.amount",
                "transaction.authType",
                "transaction.status",
                "transaction.currencyCode",
                "transaction.merchantRefNum",
                "transaction.card.brand",
                "transaction.card.country",
                "transaction.card.expiry",
                "transaction.card.lastDigits",
                "transaction.card.threeDEnrolment",
                "transaction.card.threeDResult",
                "transaction.card.type",
                "transaction.paymentType",
                "transaction.prepaidcard.lastDigits"
            ],
            "retries": 3,
            "synchronous": true
        }
    ],
    "redirect": [
        {
            "rel": "on_success",
            "uri": "http://localhost:8080/hosted_api/main/success/",
            "returnKeys": [
                "id",
                "transaction.confirmationNumber",
                "transaction.amount",
                "transaction.status",
                "transaction.errorCode",
                "transaction.errorMessage",
                "transaction.riskReasonCode",
                "transaction.card.lastDigits",
                "transaction.card.brand",
                "transaction.card.type"
            ]
        },
        {
            "rel": "on_decline",
            "uri": "http://localhost:8080/hosted_api/main/failure/",
            "returnKeys": [
                "id",
                "transaction.confirmationNumber",
                "transaction.amount",
                "transaction.status",
                "transaction.errorCode",
                "transaction.errorMessage",
                "transaction.riskReasonCode",
                "transaction.card.lastDigits",
                "transaction.card.brand",
                "transaction.card.type"
            ]
        },
        {
            "rel": "on_error",
            "uri": "http://localhost:8080/hosted_api/main/error/",
            "returnKeys": [
                "id",
                "transaction.confirmationNumber",
                "transaction.amount",
                "transaction.status",
                "transaction.errorCode",
                "transaction.errorMessage",
                "transaction.riskReasonCode",
                "transaction.card.lastDigits",
                "transaction.card.brand",
                "transaction.card.type"
            ]
        },
        {
            "rel": "on_timeout",
            "uri": "http://localhost:8080/hosted_api/main/timeout/",
            "returnKeys": [
                "id",
                "transaction.confirmationNumber",
                "transaction.amount",
                "transaction.status",
                "transaction.errorCode",
                "transaction.errorMessage",
                "transaction.riskReasonCode",
                "transaction.card.lastDigits",
                "transaction.card.brand",
                "transaction.card.type"
            ]
        },
        {
            "rel": "on_hold",
            "uri": "http://localhost:8080/hosted_api/main/onhold/",
            "returnKeys": [
                "id",
                "transaction.confirmationNumber",
                "transaction.amount",
                "transaction.status",
                "transaction.errorCode",
                "transaction.errorMessage",
                "transaction.riskReasonCode",
                "transaction.card.lastDigits",
                "transaction.card.brand",
                "transaction.card.type"
            ]
        }
    ],
    "shoppingCart": [
        {
            "amount": "1000",
            "quantity": "1",
            "description": "Fast Order"
        }
    ]
}

Here is what I am getting back as the response

{
  "error": {
    "code": 401,
    "message": "Not authorised"
  }
}

I receive the same error even if I remove the JSON code. So I am assuming that my credentials are incorrect.

    <?php
header("Content-type:application/json");
header("Authorization:application/Basic Og==");

?>

Solution

  • The information that you provided seems to be off. The Authorization in your PHP header seems to be pretty short. There could be a few reasons.

    You should be using the Base64 encoding for your key. This is what is needed in order to pass in the information in the header.

    base64_encode($APIKey)
    

    Once you do this the information will be passed in correctly. It should look like this.

    <?php
    header("Content-type:application/json");
    header("Authorization:application/Basic cTRlajZHRW5YWXJkUk9pS3JySEo6UEFBMGViNmU0M2Q2MmFkNTk5OTg");
    ?>
    

    There is also one more thing.

    I am not sure what endpoint that you are using but make sure that you are pointing to the correct place. The reason being is that when you are sending to the wrong place, it cannot validate the key and the system will just not know what you are sending in.

    Hope that this helps!