2016-07-30 10 views
0

フォーム内からchargify APIログの支払いにPOSTを発行しようとすると、問題が発生しています。PHP curl/jsonの問題POST

しかし、POSTは実際に何らかの理由でエラーを返すためGETとして送信されているようです。

誰かが私が間違っている可能性についてアドバイスを提供することはできますか? PostmanはPOSTとしてJSONを本体として送信していますが、PHPで動作させることはできません。

は(注:<urlmaskedforprivacy>は私の実際のコードでは、明らかではありません)

//find invoice id # using invoice number search form 
    $invoiceNumber = fRequest::get('invoicenumber'); 
    $json = file_get_contents('https://<maskedforprivacy>.chargify.com/invoices.json?number=' . $invoiceNumber); 
    $returnedInvData = fJSON::decode($json); 
    $invoiceId = $returnedInvData[0]->invoice->id; 


    // grab form data as payment info to send to chargify 
    $paymentAmount = fRequest::Get('amount'); 
    $memo = fRequest::Get('memo'); 

    if ((isset($invoiceNumber,$paymentAmount,$memo))) { 

    $url = 'https://<maskedforprivacy>.chargify.com/subscriptions/' . $invoiceId . '/payments.json'; 

    $params = array(
         'payment' => array(
          'amount' => $paymentAmount, 
          'memo' => (string)$memo 
        ), 
       ); 

    // encode as json    
    $content = FJSON::encode($params); 


    // send to chargify 
    $curl = curl_init($url); 
    curl_setopt($curl, CURLOPT_HEADER, false); 
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); 
    curl_setopt($curl, CURLOPT_HTTPHEADER, 
      array("Content-type: application/json")); 
    curl_setopt($curl, CURLOPT_POST, true); 
    curl_setopt($curl, CURLOPT_POSTFIELDS, $content); 

    $json_response = curl_exec($curl); 

    $status = curl_getinfo($curl, CURLINFO_HTTP_CODE); 

    if ($status != 201) { 
     die("Error: call to URL $url failed with status $status, response $json_response, curl_error " . curl_error($curl) . ", curl_errno " . curl_errno($curl)); 
    } 


    curl_close($curl); 

    $response = json_decode($json_response, true);  

    } 
+0

出力を投稿してください。 –

+0

エラー404ですが、URLが罰金です。私は郵便配達員を使用して体内にjsonを送信しても何の問題も投稿できません。 – firecasey

答えて

0

私はこの1つのコードを使用しましたが、それは401エラーを返し、基本認証を要求します。 json_response変数に格納されます。あなたがそれを逃したことがありますか?

$paymentAmount = 10; 
    $memo = 'test'; 



    $url = 'https://test.chargify.com/subscriptions/1/payments.json'; 

    $params = array(
         'payment' => array(
          'amount' => $paymentAmount, 
          'memo' => (string)$memo 
        ), 
       ); 

    // encode as json 
    $content = json_encode($params); 


    // send to chargify 
    $curl = curl_init($url); 

    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); 
    curl_setopt($curl, CURLOPT_HTTPHEADER, 
      array("Content-type: application/json")); 
    curl_setopt($curl, CURLOPT_POST, true); 
    curl_setopt($curl, CURLOPT_POSTFIELDS, $content); 

    $json_response = curl_exec($curl); 

    $status = curl_getinfo($curl, CURLINFO_HTTP_CODE); 

    if ($status != 201) { 
     die("Error: call to URL $url failed with status $status, response $json_response, curl_error " . curl_error($curl) . ", curl_errno " . curl_errno($curl)); 
    } 


    curl_close($curl); 

    $response = json_decode($json_response, true); 
+0

Authは://chargify.comを使用してURLで処理されます。プライバシーのために私のコードでそれを隠しました。 – firecasey

+0

さて、あなたのコードと同じように、私はフルモードで答えを見るためにヘッダーを削除しましたが、404エラーはありません。あなたは同じことを試みて、完全な答えを送ることができます。そうでなければ、あなたを助けることは不可能です。 – Vyacheslav