Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

按照範例程式開立發票報錯 #3

Open
smallmentor opened this issue Dec 15, 2022 · 3 comments
Open

按照範例程式開立發票報錯 #3

smallmentor opened this issue Dec 15, 2022 · 3 comments

Comments

@smallmentor
Copy link

您好 我使用1.2版的SDK
並且按照該範例中的程式碼試圖開立發票
但是SDK報錯如下:Response is not JSON format
發生在:
ecpay\sdk\src\Response\AesJsonResponse.php
Line: 22

看到錯誤訊息後,我嘗試對$input進行json_encode,得到錯誤:uksort() expects parameter 1 to be array, string given
發生在:
ecpay\sdk\src\Services\ArrayService.php
Line: 18

我有注意到1.2版與1.1版使用的ResponseInterface不一樣(AbstractDecryptedResponseAbstractAesResponse),所以這個範例可能需要進行更新,請問可以提供新版本的範例程式碼嗎?

感謝您

@smallmentor
Copy link
Author

以下是我的程式碼,希望對您有幫助

      /**
       * @var \Ecpay\Sdk\Services\PostService
       */
      $postService = $this->factory->create('PostWithAesJsonResponseService');

      $input = [
          'MerchantID' => $this->merchantId,
          'RqHeader' => [
              'Timestamp' => time(),
              'Revision' => '3.0.0',
          ],
          'Data' => [
              'MerchantID' => $this->merchantId,
              'RelateNumber' => data_get($order, 'RelateNumber', ''), // 特店自訂編號
              'CustomerName' => data_get($order, 'CustomerName', ''), // 客戶名稱
              'CustomerAddr' => data_get($order, 'CustomerAddr', ''), // 客戶地址
              'CustomerPhone' => data_get($order, 'CustomerPhone', ''), // 客戶手機號碼
              'CustomerEmail' => data_get($order, 'CustomerEmail', ''), // 客戶電子信箱
              'Donation' => '0', // 不捐贈
              //'LoveCode' => '', // 無捐贈碼
              'Print' => '1', // 開立發票
              'CarrierType' => '', // 無載具
              'TaxType' => '1', // 課稅類別: 應稅
              'SalesAmount' => intval(data_get($order, 'SalesAmount', 1)), // 發票總金額(含稅)
              'Items' => data_get($order, 'Items', []), // 商品明細
              'InvType' => '07',
          ],
      ];

      $response = $postService->post(json_encode($input), $this->apiUrl . '/B2CInvoice/Issue');

@AllennChang
Copy link
Contributor

您好, 已收到您的問題反應, 我們會請開發團隊進行測試及調整, 感謝您提供的回饋

@AllennChang
Copy link
Contributor

您好, 經開發團隊進行測試後發現是沒問題的, 請檢查您送出的資料$input 的資料格式是否為正常json格式, 感謝

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants