当我尝试向 Paysafe 发送请求时,我不断收到来自 API 的以下响应
When I try to send a request to Paysafe, I keep getting the following response form the API
这是我用来提出请求的代码。
{
"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"
}
]
}
这是我收到的回复
{
"error": {
"code": 401,
"message": "Not authorised"
}
}
即使删除 JSON 代码,我也会收到同样的错误。所以我假设我的凭据不正确。
<?php
header("Content-type:application/json");
header("Authorization:application/Basic Og==");
?>
您提供的信息似乎有误。您的 PHP header 中的授权似乎很短。可能有几个原因。
您的密钥应该使用 Base64 编码。这是传递 header 中的信息所需要的。
base64_encode($APIKey)
执行此操作后,信息将正确传递。它应该是这样的。
<?php
header("Content-type:application/json");
header("Authorization:application/Basic cTRlajZHRW5YWXJkUk9pS3JySEo6UEFBMGViNmU0M2Q2MmFkNTk5OTg");
?>
还有一件事。
我不确定您使用的是哪个端点,但请确保您指向的是正确的位置。原因是当您发送到错误的地方时,它无法验证密钥,系统将不知道您发送的是什么。
希望对您有所帮助!
这是我用来提出请求的代码。
{
"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"
}
]
}
这是我收到的回复
{
"error": {
"code": 401,
"message": "Not authorised"
}
}
即使删除 JSON 代码,我也会收到同样的错误。所以我假设我的凭据不正确。
<?php
header("Content-type:application/json");
header("Authorization:application/Basic Og==");
?>
您提供的信息似乎有误。您的 PHP header 中的授权似乎很短。可能有几个原因。
您的密钥应该使用 Base64 编码。这是传递 header 中的信息所需要的。
base64_encode($APIKey)
执行此操作后,信息将正确传递。它应该是这样的。
<?php
header("Content-type:application/json");
header("Authorization:application/Basic cTRlajZHRW5YWXJkUk9pS3JySEo6UEFBMGViNmU0M2Q2MmFkNTk5OTg");
?>
还有一件事。
我不确定您使用的是哪个端点,但请确保您指向的是正确的位置。原因是当您发送到错误的地方时,它无法验证密钥,系统将不知道您发送的是什么。
希望对您有所帮助!