title: Can I use $transaction->setReferenceId() with Paypal PHP REST API?
body: <p>I'm trying to include a identifier in the transaction so I know which transaction is when it returns from Paypal. I've tried to use the reference_id as it's like the better option (because is a temporal identifier that I assign to the transaction).</p>
  
  <p>The problem is that when I set it to the transaction, Paypal refuse to accept the json, it returns:</p>
  
  <pre><code>{
     "name":"MALFORMED_REQUEST",
     "message":"Incoming JSON request does not map to API request",
     "information_link":"https://developer.paypal.com/webapps/developer/docs/api/#MALFORMED_REQUEST",
     "debug_id":"6835f984b6735"
  }
  </code></pre>
  
  <p>More or less I use the example code:</p>
  
  <pre><code>// Create new payer and method
  $payer = new Payer();
  $payer-&gt;setPaymentMethod("paypal");
  
  // Set redirect urls
  $redirectUrls = new RedirectUrls();
  $redirectUrls-&gt;setReturnUrl($urlRetorno)
      -&gt;setCancelUrl($urlCancelar);
  
  // Set payment amount
  $amount = new Amount();
  $amount-&gt;setCurrency($moneda)
      -&gt;setTotal($total);
  
  // Set transaction object
  $transaction = new Transaction();
  $transaction-&gt;setAmount($amount)
      -&gt;setDescription($descripcion);
  
  // If I comment this line it runs ok.
  $transaction-&gt;setReferenceId($referenceId);
  
  // Create the full payment object
  $payment = new Payment();
  $payment-&gt;setIntent('sale')
      -&gt;setPayer($payer)
      -&gt;setRedirectUrls($redirectUrls)
      -&gt;setTransactions(array($transaction));
  
  echo $payment-&gt;toJSON();
  
  // Create payment with valid API context
  try {
  
      $payment-&gt;create($apiContext);
  
      // Get PayPal redirect URL and redirect user
      $approvalUrl = $payment-&gt;getApprovalLink();
  
      // Finalmente le redirigimos a PayPal para que apruebe el pago
      //redirige($approvalUrl, 'Intentando redirigir a PayPal.');
  
  } catch (PayPal\Exception\PayPalConnectionException $ex) {
      echo $ex-&gt;getCode();
      echo $ex-&gt;getData();
      die($ex);
  } catch (Exception $ex) {
      die($ex);
  }
  </code></pre>
  
  <p>And this is the result (calling toJSON()):</p>
  
  <pre><code>{
     "intent":"sale",
     "payer":{
        "payment_method":"paypal"
     },
     "redirect_urls":{
        "return_url":"https://example.com/return.php",
        "cancel_url":"https://example.com/cancel.php"
     },
     "transactions":[
        {
           "amount":{
              "currency":"MXN",
              "total":"1515"
           },
           "description":"Suscripci\u00f3n c\u00f3digo PP-19119",
           "reference_id":"304171757041"
        }
     ]
  }
  </code></pre>
  
  <p>I have found the <a href="https://developer.paypal.com/docs/api/payments/#definition-transaction" rel="nofollow noreferrer">reference_id in the API documentation</a> so I supposed I could use it.</p>