简体   繁体   English

PHP curl_setopt 错误

[英]PHP curl_setopt errors

Error received is:收到的错误是:

{
  "code": "INVALID_REQUEST",
  "message": "Invalid request",
  "errors": [
    {
      "code": "MANDATORY_FIELD_MISSING",
      "message": "a mandatory field is missing",
      "path": "/periodKey"
    },
    {
      "code": "MANDATORY_FIELD_MISSING",
      "message": "a mandatory field is missing",
      "path": "/vatDueSales"
    },
    {
      "code": "MANDATORY_FIELD_MISSING",
      "message": "a mandatory field is missing",
      "path": "/vatDueAcquisitions"
    },
    {
      "code": "MANDATORY_FIELD_MISSING",
      "message": "a mandatory field is missing",
      "path": "/totalVatDue"
    },
    {
      "code": "MANDATORY_FIELD_MISSING",
      "message": "a mandatory field is missing",
      "path": "/vatReclaimedCurrPeriod"
    },
    {
      "code": "MANDATORY_FIELD_MISSING",
      "message": "a mandatory field is missing",
      "path": "/netVatDue"
    },
    {
      "code": "MANDATORY_FIELD_MISSING",
      "message": "a mandatory field is missing",
      "path": "/totalValueSalesExVAT"
    },
    {
      "code": "MANDATORY_FIELD_MISSING",
      "message": "a mandatory field is missing",
      "path": "/totalValuePurchasesExVAT"
    },
    {
      "code": "MANDATORY_FIELD_MISSING",
      "message": "a mandatory field is missing",
      "path": "/totalValueGoodsSuppliedExVAT"
    },
    {
      "code": "MANDATORY_FIELD_MISSING",
      "message": "a mandatory field is missing",
      "path": "/totalAcquisitionsExVAT"
    },
    {
      "code": "MANDATORY_FIELD_MISSING",
      "message": "a mandatory field is missing",
      "path": "/finalised"
    }
  ]
}

my code is:我的代码是:

$headerData = [
    'Accept: application/vnd.hmrc.1.0+json',
    'Authorization: Bearer ' . $strAccessToken ,
    'Content-Type: application/json'
];
$postData = json_encode(array(
    'periodKey' => $strPeriodKey ,
    'vatDueSales' => $rngBox1 ,
    'vatDueAcquisitions' => $rngBox2 ,
    'totalVatDue' => $rngBox3 ,
    'vatReclaimedCurrPeriod' => $rngBox4 ,
    'netVatDue' => $rngBox5 ,
    'totalValueSalesExVAT' => $rngBox6 ,
    'totalValuePurchasesExVAT' => $rngBox7 ,
    'totalValueGoodsSuppliedExVAT' => $rngBox8 ,
    'totalAcquisitionsExVAT' => $rngBox9 ,
    'finalised' => $chkFinaliseConfirm
)); 

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,           $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_POST,          1);
curl_setopt($ch, CURLOPT_POSTFIELDS,    $postData);
curl_setopt($ch, CURLOPT_HTTPHEADER,    $headerData);
$data = curl_exec($ch);
curl_close($ch);

Endpoint info can be found here: https://developer.service.hmrc.gov.uk/api-documentation/docs/api/service/vat-api/1.0 but in principle is:端点信息可以在这里找到: https://developer.service.hmrc.gov.uk/api-documentation/docs/api/service/vat-api/1.0但原则上是:

/organisations/vat/{vrn}/returns /organisations/vat/{vrn}/returns

Submit VAT return for period POST Submit VAT return for period POST Submit VAT return for period.提交期间 POST 的增值税申报表 提交期间的增值税申报表 POST 提交期间的增值税申报表。 This endpoint is one of the mandatory endpoints to use to achieve the minimum level of compliance.此端点是用于实现最低合规级别的强制端点之一。 The other endpoint required to achieve the minimum level of compliance is Retrieve VAT obligations.实现最低合规水平所需的另一个端点是检索增值税义务。

Authorisation This endpoint is user-restricted and requires an Authorization header containing an OAuth 2.0 Bearer Token with the write:vat scope.授权 此端点受用户限制,需要授权 header,其中包含 OAuth 2.0 Bearer Token 和 write:vat scope。

Path parameters Path parameters table Name Description vrn string required VAT registration number.路径参数 路径参数表 名称 描述 vrn 字符串 需要增值税登记号。 A nine-digit number.一个九位数字。

For example: 123456789例如:123456789

Request headers Request headers Table Name Description Accept required Specifies the response format and the version of the API to be used.请求头 请求头 表名 描述 Accept required 指定响应格式和要使用的 API 的版本。

For example: application/vnd.hmrc.1.0+json Content-Type required Specifies the format of the request body, which must be JSON.例如:application/vnd.hmrc.1.0+json Content-Type required 指定请求体的格式,必须是JSON。

For example: application/json Gov-Test-Scenario optional Only in sandbox environment.例如:application/json Gov-Test-Scenario optional 仅在沙盒环境中。 See Test Data table for all header values.请参阅测试数据表了解所有 header 值。

For example: - Authorization required An OAuth 2.0 Bearer Token with the write:vat scope.例如: - 需要授权 OAuth 2.0 Bearer Token with write:vat scope。

For example: Bearer bb7fed3fe10dd235a2ccda3d50fb See also fraud prevention.例如:不记名 bb7fed3fe10dd235a2ccda3d50fb 另请参阅防欺诈。

Request Scenario: VAT Return with decimals { "periodKey": "A001",请求场景:小数点增值税退税 { "periodKey": "A001",
"vatDueSales": 105.50, "vatDueAcquisitions": -100.45, “vatDueSales”:105.50,“vatDueAcquisitions”:-100.45,
"totalVatDue": 5.05, "vatReclaimedCurrPeriod": 105.15, “totalVatDue”:5.05,“vatReclaimedCurrPeriod”:105.15,
"netVatDue": 100.10, "totalValueSalesExVAT": 300, “netVatDue”:100.10,“totalValueSalesExVAT”:300,
"totalValuePurchasesExVAT": 300, "totalValueGoodsSuppliedExVAT": 3000, "totalAcquisitionsExVAT": 3000, "finalised": true } Scenario: VAT Return with a hash in the periodKey { "periodKey": "#001", "vatDueSales": 100.00, "vatDueAcquisitions": 100.00, "totalValuePurchasesExVAT": 300, "totalValueGoodsSuppliedExVAT": 3000, "totalAcquisitionsExVAT": 3000, "finalised": true } 场景:在 periodKey { "periodKey", "#001", "00.vat:" "vatDueAcquisitions": 100.00,
"totalVatDue": 200.00, "vatReclaimedCurrPeriod": 100.00, “totalVatDue”:200.00,“vatReclaimedCurrPeriod”:100.00,
"netVatDue": 100.00, "totalValueSalesExVAT": 500, “netVatDue”:100.00,“totalValueSalesExVAT”:500,
"totalValuePurchasesExVAT": 500, "totalValueGoodsSuppliedExVAT": 500, "totalAcquisitionsExVAT": 500, "finalised": true } Request table Name Description periodKey string required The ID code for the period that this obligation belongs to. "totalValuePurchasesExVAT": 500, "totalValueGoodsSuppliedExVAT": 500, "totalAcquisitionsExVAT": 500, "finalised": true } 请求表名称 描述 periodKey string required 此义务所属期间的 ID 代码。 The format is a string of four alphanumeric characters.格式是一个由四个字母数字字符组成的字符串。 Occasionally the format includes the # symbol.有时该格式包含# 符号。

For example: 18AD, 18A1, #001例如:18AD、18A1、#001

vatDueSales number required VAT due on sales and other outputs. vatDueSales number required 销售和其他输出应缴纳的增值税。 This corresponds to box 1 on the VAT Return form.这对应于增值税申报表上的方框 1。 The value must be between -9999999999999.99 and 9999999999999.99.该值必须介于 -9999999999999.99 和 9999999999999.99 之间。

vatDueAcquisitions number required VAT due on acquisitions from other EC Member States. vatDueAcquisitions number required 来自其他 EC 成员国的采购应缴纳的增值税。 This corresponds to box 2 on the VAT Return form.这对应于增值税申报表上的方框 2。 The value must be between -9999999999999.99 and 9999999999999.99.该值必须介于 -9999999999999.99 和 9999999999999.99 之间。

totalVatDue number required Total VAT due (the sum of vatDueSales and vatDueAcquisitions). totalVatDue number required 总增值税(vatDueSales 和vatDueAcquisitions 的总和)。 This corresponds to box 3 on the VAT Return form.这对应于增值税申报表上的方框 3。 The value must be between -9999999999999.99 and 9999999999999.99.该值必须介于 -9999999999999.99 和 9999999999999.99 之间。

vatReclaimedCurrPeriod number required VAT reclaimed on purchases and other inputs (including acquisitions from the EC). vatReclaimedCurrPeriod number required 对采购和其他投入(包括从 EC 的收购)征收的增值税。 This corresponds to box 4 on the VAT Return form.这对应于增值税申报表上的方框 4。 The value must be between -9999999999999.99 and 9999999999999.99.该值必须介于 -9999999999999.99 和 9999999999999.99 之间。

netVatDue number required The difference between totalVatDue and vatReclaimedCurrPeriod. netVatDue number required totalVatDue 和 vatReclaimedCurrPeriod 之间的差异。 This corresponds to box 5 on the VAT Return form.这对应于增值税申报表上的方框 5。 The value must be between 0.00 and 99999999999.99该值必须介于 0.00 和 99999999999.99 之间

totalValueSalesExVAT number required Total value of sales and all other outputs excluding any VAT.需要 totalValueSalesExVAT 编号 销售额和所有其他输出的总价值,不包括任何增值税。 This corresponds to box 6 on the VAT Return form.这对应于增值税申报表上的方框 6。 The value must be in pounds (no pence) between -9999999999999 and 9999999999999.该值必须在 -9999999999999 和 9999999999999 之间以磅(无便士)为单位。

totalValuePurchasesExVAT number required Total value of purchases and all other inputs excluding any VAT (including exempt purchases). totalValuePurchasesExVAT number required 购买和所有其他投入的总价值,不包括任何增值税(包括免税购买)。 This corresponds to box 7 on the VAT Return form.这对应于增值税申报表上的方框 7。 The value must be in pounds (no pence) between -9999999999999 and 9999999999999.该值必须在 -9999999999999 和 9999999999999 之间以磅(无便士)为单位。

totalValueGoodsSuppliedExVAT number required Total value of all supplies of goods and related costs, excluding any VAT, to other EC member states. totalValueGoodsSuppliedExVAT number required 向其他 EC 成员国供应的所有商品和相关成本的总价值,不包括任何增值税。 This corresponds to box 8 on the VAT Return form.这对应于增值税申报表上的方框 8。 The value must be between -9999999999999 and 9999999999999.该值必须介于 -9999999999999 和 9999999999999 之间。

totalAcquisitionsExVAT number required Total value of acquisitions of goods and related costs excluding any VAT, from other EC member states. totalAcquisitionsExVAT number required 来自其他欧共体成员国的商品采购总值和相关成本,不包括任何增值税。 This corresponds to box 9 on the VAT Return form.这对应于增值税申报表上的方框 9。 The value must be between -9999999999999 and 9999999999999.该值必须介于 -9999999999999 和 9999999999999 之间。

finalised boolean required Declaration that the user has finalised their VAT return. finalized boolean 要求 声明用户已完成增值税申报。

For example: true例如:真

Response headers Response headers Table Name Description X-CorrelationId required Unique id for operation tracking String, 36 characters.响应头 响应头 表名 描述 X-CorrelationId 要求 操作跟踪的唯一 id 字符串,36 个字符。

For example: c75f40a6-a3df-4429-a697-471eeec46435 Receipt-ID required Unique reference number returned for a submission String, 36 characters.例如:c75f40a6-a3df-4429-a697-471eeec46435 需要收据 ID 为提交字符串返回的唯一参考号,36 个字符。

For example: 2dd537bc-4244-4ebf-bac9-96321be13cdc Receipt-Timestamp required The timestamp from the signature, in ISO8601 format例如:2dd537bc-4244-4ebf-bac9-96321be13cdc Receipt-Timestamp required 来自签名的时间戳,采用 ISO8601 格式

For example: 2018-02-14T09:32:15Z Receipt-Signature required This header is not currently used例如:2018-02-14T09:32:15Z Receipt-Signature required This header 当前未使用

For example: DO NOT USE See also fraud prevention.例如:请勿使用 另请参阅防欺诈。

Response HTTP status: 201 (Created)响应 HTTP 状态:201(已创建)

{ "processingDate": "2018-01-16T08:20:27.895+0000", { "处理日期": "2018-01-16T08:20:27.895+0000",
"paymentIndicator": "BANK", "formBundleNumber": "256660290587", “paymentIndicator”:“银行”,“formBundleNumber”:“256660290587”,
"chargeRefNumber": "aCxFaNx0FZsCvyWF" } Response table Name Description processingDate string required The time that the message was processed in the system. "chargeRefNumber": "aCxFaNx0FZsCvyWF" } 响应表 名称 描述 processingDate string required 消息在系统中处理的时间。

formBundleNumber string required Unique number that represents the form bundle. formBundleNumber string required 代表表单包的唯一编号。 The system stores VAT Return data in forms, which are held in a unique form bundle.系统将增值税退税数据存储在 forms 中,这些数据以唯一的表单捆绑包形式保存。

Must conform to the regular expression ^[0-9]{12}$必须符合正则表达式^[0-9]{12}$

paymentIndicator string optional Is DD if the netVatDue value is a debit and HMRC holds a Direct Debit Instruction for the client. paymentIndicator 字符串 可选 如果 netVatDue 值是借记并且 HMRC 持有客户的直接借记指令,则为 DD。 Is BANK if the netVatDue value is a credit and HMRC holds the client's bank data.如果 netVatDue 值是信用并且 HMRC 持有客户的银行数据,则为 BANK。 Otherwise not present.否则不存在。

Limited to the following possible values:限于以下可能的值:

DD BANK chargeRefNumber string optional The charge reference number is returned, only if the netVatDue value is a debit. DD BANK chargeRefNumber 字符串 可选 仅当 netVatDue 值为借方时才返回费用参考号。 Between 1 and 16 characters.介于 1 到 16 个字符之间。

Error scenarios Error scenarios table Scenario HTTP status Code Invalid VRN错误场景 错误场景表 场景 HTTP 状态码 无效 VRN

400 (Bad Request) 400(错误请求)

VRN_INVALID VRN_INVALID

Invalid period key无效的期间键

400 (Bad Request) 400(错误请求)

PERIOD_KEY_INVALID PERIOD_KEY_INVALID

Invalid request无效的请求

400 (Bad Request) 400(错误请求)

INVALID_REQUEST无效的请求

totalVatDue should be equal to the sum of vatDueSales and vatDueAcquisitions totalVatDue 应等于 vatDueSales 和 vatDueAcquisitions 之和

400 (Bad Request) 400(错误请求)

VAT_TOTAL_VALUE增值税_TOTAL_VALUE

netVatDue should be the difference between the largest and the smallest values among totalVatDue and vatReclaimedCurrPeriod netVatDue 应该是 totalVatDue 和 vatReclaimedCurrPeriod 之间的最大值和最小值之差

400 (Bad Request) 400(错误请求)

VAT_NET_VALUE VAT_NET_VALUE

Please provide a numeric field请提供一个数字字段

400 (Bad Request) 400(错误请求)

INVALID_NUMERIC_VALUE INVALID_NUMERIC_VALUE

The monetary amount is invalid金额无效

400 (Bad Request) 400(错误请求)

INVALID_MONETARY_AMOUNT INVALID_MONETARY_AMOUNT

User has not declared VAT return as final用户尚未将增值税申报表申报为最终申报表

403 (Forbidden) 403(禁止)

NOT_FINALISED NOT_FINALISED

User has already submitted a VAT return for the given period用户已提交给定期间的增值税申报表

403 (Forbidden) 403(禁止)

DUPLICATE_SUBMISSION DUPLICATE_SUBMISSION

Return submitted too early退货提交过早

403 (Forbidden) 403(禁止)

TAX_PERIOD_NOT_ENDED TAX_PERIOD_NOT_ENDED

The client and/or agent is not authorised.客户和/或代理未经授权。 This is normally because: the client is not subscribed to MTD, the agent is not subscribed to Agent Services, or the client has not authorised the agent to act on their behalf.这通常是因为:客户未订阅 MTD,代理未订阅代理服务,或客户未授权代理代表他们行事。

403 (Forbidden) 403(禁止)

CLIENT_OR_AGENT_NOT_AUTHORISED CLIENT_OR_AGENT_NOT_AUTHORISED

The request could not be completed as it relates to an insolvent trader, which are not supported by this API.该请求无法完成,因为它与破产交易者有关,此 API 不支持。

403 (Forbidden) 403(禁止)

RULE_INSOLVENT_TRADER RULE_INSOLVENT_TRADER

For error scenarios that are common across all APIs, and for error formats, see our reference guide.对于所有 API 中常见的错误场景以及错误格式,请参阅我们的参考指南。

Test data Scenario simulations using Gov-Test-Scenario headers are only available in sandbox environment.使用 Gov-Test-Scenario 标头的测试数据场景模拟仅在沙盒环境中可用。

Using this endpoint in the sandbox environment will store the data submitted.在沙盒环境中使用此端点将存储提交的数据。 There is no requirement to use the periodKeys in the obligation response in the sandbox environment.在沙盒环境中的义务响应中不需要使用 periodKeys。

Header Value (Gov-Test-Scenario) Scenario INVALID_VRN Header 值(Gov-Test-Scenario) 场景 INVALID_VRN

Submission has not passed validation.提交未通过验证。 Invalid parameter VRN.参数 VRN 无效。

INVALID_PERIODKEY INVALID_PERIODKEY

Submission has not passed validation.提交未通过验证。 Invalid parameter PERIODKEY.参数 PERIODKEY 无效。

INVALID_PAYLOAD INVALID_PAYLOAD

Submission has not passed validation.提交未通过验证。 Invalid parameter Payload.参数负载无效。

DUPLICATE_SUBMISSION DUPLICATE_SUBMISSION

The remote endpoint has indicated that VAT has already been submitted for that period.远程端点已指示该期间的增值税已提交。

TAX_PERIOD_NOT_ENDED TAX_PERIOD_NOT_ENDED

The remote endpoint has indicated that the submission is for a tax period that has not ended.远程端点已指示提交是针对尚未结束的纳税期。

INSOLVENT_TRADER INSOLVENT_TRADER

Simulates the scenario where the client is an insolvent trader.模拟客户是资不抵债的交易者的场景。

Close section关闭部分

I've tried changing the format of post data into an array using different methods but none of them seem to like the format I am passing.我尝试使用不同的方法将发布数据的格式更改为数组,但它们似乎都不喜欢我传递的格式。 Question is why am I getting the above error messages when I am using the above code?问题是为什么我在使用上述代码时会收到上述错误消息?

tia m@蒂亚米@

Try url encoded post:尝试 url 编码后:

$headerData = [
    'Accept: application/vnd.hmrc.1.0+json',
    'Authorization: Bearer ' . $strAccessToken ,
    'Content-Type: application/json'
];
$postData = array(
    'periodKey' => $strPeriodKey ,
    'vatDueSales' => $rngBox1 ,
    'vatDueAcquisitions' => $rngBox2 ,
    'totalVatDue' => $rngBox3 ,
    'vatReclaimedCurrPeriod' => $rngBox4 ,
    'netVatDue' => $rngBox5 ,
    'totalValueSalesExVAT' => $rngBox6 ,
    'totalValuePurchasesExVAT' => $rngBox7 ,
    'totalValueGoodsSuppliedExVAT' => $rngBox8 ,
    'totalAcquisitionsExVAT' => $rngBox9 ,
    'finalised' => $chkFinaliseConfirm
); 

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,           $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_POST,          1);
curl_setopt($ch, CURLOPT_POSTFIELDS,    $postData);
curl_setopt($ch, CURLOPT_HTTPHEADER,    $headerData);
$data = curl_exec($ch);
curl_close($ch);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM