ECPay / SDK_PHP

30 stars 13 forks source link

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

Open smallmentor opened 1 year ago

smallmentor commented 1 year ago

您好 我使用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 commented 1 year ago

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

      /**
       * @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 commented 1 year ago

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

AllennChang commented 1 year ago

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