<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>thread Re: PHP code always ends with caught exception in Archived Discussions (Read Only)</title>
    <link>https://community.squareup.com/t5/Archived-Discussions-Read-Only/PHP-code-always-ends-with-caught-exception/m-p/39599#M55565</link>
    <description>&lt;P&gt;Thanks, but that doesn't appear to be a valid link.&lt;/P&gt;</description>
    <pubDate>Fri, 02 Jun 2017 18:56:23 GMT</pubDate>
    <dc:creator>JobChunk</dc:creator>
    <dc:date>2017-06-02T18:56:23Z</dc:date>
    <item>
      <title>PHP code always ends with caught exception</title>
      <link>https://community.squareup.com/t5/Archived-Discussions-Read-Only/PHP-code-always-ends-with-caught-exception/m-p/39528#M55561</link>
      <description>&lt;P&gt;I developing a site to accept customer payments for a product, and I need to allow the customer to enter there credit card information and place an order for the product. I've downloaded sample code from the git site, along with all of the other recommended code. When I try to process a card using the sandbox, I get all o the way through to where the $transaction_api attempts to charge the card. Then I get back "Caught exception! Response body: NULL Response headers: NULL"&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;At this point I'm stuck. I researched everything that i can find, and I don't see an answer.&lt;/P&gt;</description>
      <pubDate>Thu, 01 Jun 2017 20:45:34 GMT</pubDate>
      <guid>https://community.squareup.com/t5/Archived-Discussions-Read-Only/PHP-code-always-ends-with-caught-exception/m-p/39528#M55561</guid>
      <dc:creator>JobChunk</dc:creator>
      <dc:date>2017-06-01T20:45:34Z</dc:date>
    </item>
    <item>
      <title>Re: PHP code always ends with caught exception</title>
      <link>https://community.squareup.com/t5/Archived-Discussions-Read-Only/PHP-code-always-ends-with-caught-exception/m-p/39530#M55562</link>
      <description>&lt;P&gt;Welcome! I'm running this question by our Developers team to get more information for you. Be back soon!&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":smiling_face_with_smiling_eyes:"&gt;😊&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 01 Jun 2017 20:45:15 GMT</pubDate>
      <guid>https://community.squareup.com/t5/Archived-Discussions-Read-Only/PHP-code-always-ends-with-caught-exception/m-p/39530#M55562</guid>
      <dc:creator>Caty</dc:creator>
      <dc:date>2017-06-01T20:45:15Z</dc:date>
    </item>
    <item>
      <title>Re: PHP code always ends with caught exception</title>
      <link>https://community.squareup.com/t5/Archived-Discussions-Read-Only/PHP-code-always-ends-with-caught-exception/m-p/39541#M55563</link>
      <description>&lt;P&gt;Thank you Caty.&lt;/P&gt;</description>
      <pubDate>Thu, 01 Jun 2017 21:19:30 GMT</pubDate>
      <guid>https://community.squareup.com/t5/Archived-Discussions-Read-Only/PHP-code-always-ends-with-caught-exception/m-p/39541#M55563</guid>
      <dc:creator>JobChunk</dc:creator>
      <dc:date>2017-06-01T21:19:30Z</dc:date>
    </item>
    <item>
      <title>Re: PHP code always ends with caught exception</title>
      <link>https://community.squareup.com/t5/Archived-Discussions-Read-Only/PHP-code-always-ends-with-caught-exception/m-p/39585#M55564</link>
      <description>&lt;P&gt;That example is meant to use an older version of the PHP SDK.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try using the code in this branch:&lt;A href="https://github.com/square/connect-api-examples/blob/feature/migrate-to-2.1.0/connect-examples/v2.1/php_payment/process-card.php" target="_blank"&gt;https://github.com/square/connect-api-examples/blob/feature/migrate-to-2.1.0/connect-examples/v2.1/php_payment/process-card.php&lt;/A&gt; for the time being.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 02 Jun 2017 16:15:23 GMT</pubDate>
      <guid>https://community.squareup.com/t5/Archived-Discussions-Read-Only/PHP-code-always-ends-with-caught-exception/m-p/39585#M55564</guid>
      <dc:creator>tristansokol</dc:creator>
      <dc:date>2017-06-02T16:15:23Z</dc:date>
    </item>
    <item>
      <title>Re: PHP code always ends with caught exception</title>
      <link>https://community.squareup.com/t5/Archived-Discussions-Read-Only/PHP-code-always-ends-with-caught-exception/m-p/39599#M55565</link>
      <description>&lt;P&gt;Thanks, but that doesn't appear to be a valid link.&lt;/P&gt;</description>
      <pubDate>Fri, 02 Jun 2017 18:56:23 GMT</pubDate>
      <guid>https://community.squareup.com/t5/Archived-Discussions-Read-Only/PHP-code-always-ends-with-caught-exception/m-p/39599#M55565</guid>
      <dc:creator>JobChunk</dc:creator>
      <dc:date>2017-06-02T18:56:23Z</dc:date>
    </item>
    <item>
      <title>Re: PHP code always ends with caught exception</title>
      <link>https://community.squareup.com/t5/Archived-Discussions-Read-Only/PHP-code-always-ends-with-caught-exception/m-p/39600#M55566</link>
      <description>&lt;P&gt;The master branch has been updated now.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 02 Jun 2017 19:07:59 GMT</pubDate>
      <guid>https://community.squareup.com/t5/Archived-Discussions-Read-Only/PHP-code-always-ends-with-caught-exception/m-p/39600#M55566</guid>
      <dc:creator>tristansokol</dc:creator>
      <dc:date>2017-06-02T19:07:59Z</dc:date>
    </item>
    <item>
      <title>Re: PHP code always ends with caught exception</title>
      <link>https://community.squareup.com/t5/Archived-Discussions-Read-Only/PHP-code-always-ends-with-caught-exception/m-p/40150#M55567</link>
      <description>&lt;P&gt;Hi i am having the same issue&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Caught exception!&lt;/SPAN&gt;&lt;BR /&gt;&lt;STRONG&gt;Response body:&lt;/STRONG&gt;&lt;/P&gt;
&lt;PRE&gt;NULL
&lt;/PRE&gt;
&lt;P&gt;&lt;BR /&gt;&lt;STRONG&gt;Response headers:&lt;/STRONG&gt;&lt;/P&gt;
&lt;PRE&gt;NULL&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;the given url is invalid. how can i resolve it using sandbox&lt;/P&gt;</description>
      <pubDate>Sat, 10 Jun 2017 06:14:58 GMT</pubDate>
      <guid>https://community.squareup.com/t5/Archived-Discussions-Read-Only/PHP-code-always-ends-with-caught-exception/m-p/40150#M55567</guid>
      <dc:creator>QaisarMalik</dc:creator>
      <dc:date>2017-06-10T06:14:58Z</dc:date>
    </item>
    <item>
      <title>Re: PHP code always ends with caught exception</title>
      <link>https://community.squareup.com/t5/Archived-Discussions-Read-Only/PHP-code-always-ends-with-caught-exception/m-p/40152#M55568</link>
      <description>&lt;P&gt;This is the code that I found that actually works:&lt;/P&gt;
&lt;P&gt;&amp;lt;?php&lt;BR /&gt;require 'vendor/autoload.php';&lt;BR /&gt;# Replace these values. You probably want to start with your Sandbox credentials&lt;BR /&gt;# to start: &lt;A href="https://docs.connect.squareup.com/articles/using-sandbox/" target="_blank"&gt;https://docs.connect.squareup.com/articles/using-sandbox/&lt;/A&gt;&lt;BR /&gt;# The access token to use in all Connect API requests. Use your *sandbox* access&lt;BR /&gt;# token if you're just testing things out.&lt;BR /&gt;$access_token = '';&lt;BR /&gt;# Helps ensure this code has been reached via form submission&lt;BR /&gt;if ($_SERVER['REQUEST_METHOD'] != 'POST') {&lt;BR /&gt; error_log("Received a non-POST request");&lt;BR /&gt; echo "Request not allowed";&lt;BR /&gt; http_response_code(405);&lt;BR /&gt; return;&lt;BR /&gt;}&lt;BR /&gt;# Fail if the card form didn't send a value for `nonce` to the server&lt;BR /&gt;$nonce = $_POST['nonce'];&lt;BR /&gt;if (is_null($nonce)) {&lt;BR /&gt; echo "Invalid card data";&lt;BR /&gt; http_response_code(422);&lt;BR /&gt; return;&lt;BR /&gt;}&lt;BR /&gt;\SquareConnect\Configuration::getDefaultConfiguration()-&amp;gt;setAccessToken($access_token);&lt;BR /&gt;$locations_api = new \SquareConnect\Api\LocationsApi();&lt;BR /&gt;try {&lt;BR /&gt; $locations = $locations_api-&amp;gt;listLocations();&lt;BR /&gt; #We look for a location that can process payments&lt;BR /&gt; $location = current(array_filter($locations-&amp;gt;getLocations(), function($location) {&lt;BR /&gt; return !empty($location-&amp;gt;getCapabilities()) &amp;amp;&amp;amp;&lt;BR /&gt; in_array('CREDIT_CARD_PROCESSING', $location-&amp;gt;getCapabilities());&lt;BR /&gt; }));&lt;BR /&gt;} catch (\SquareConnect\ApiException $e) {&lt;BR /&gt; echo "Caught exception!&amp;lt;br/&amp;gt;";&lt;BR /&gt; print_r("&amp;lt;strong&amp;gt;Response body:&amp;lt;/strong&amp;gt;&amp;lt;br/&amp;gt;");&lt;BR /&gt; echo "&amp;lt;pre&amp;gt;"; var_dump($e-&amp;gt;getResponseBody()); echo "&amp;lt;/pre&amp;gt;";&lt;BR /&gt; echo "&amp;lt;br/&amp;gt;&amp;lt;strong&amp;gt;Response headers:&amp;lt;/strong&amp;gt;&amp;lt;br/&amp;gt;";&lt;BR /&gt; echo "&amp;lt;pre&amp;gt;"; var_dump($e-&amp;gt;getResponseHeaders()); echo "&amp;lt;/pre&amp;gt;";&lt;BR /&gt; exit(1);&lt;BR /&gt;}&lt;BR /&gt;$transactions_api = new \SquareConnect\Api\TransactionsApi();&lt;BR /&gt;$request_body = array (&lt;BR /&gt; "card_nonce" =&amp;gt; $nonce,&lt;BR /&gt; # Monetary amounts are specified in the smallest unit of the applicable currency.&lt;BR /&gt; # This amount is in cents. It's also hard-coded for $1.00, which isn't very useful.&lt;BR /&gt; "amount_money" =&amp;gt; array (&lt;BR /&gt; "amount" =&amp;gt; 100,&lt;BR /&gt; "currency" =&amp;gt; "USD"&lt;BR /&gt; ),&lt;BR /&gt; # Every payment you process with the SDK must have a unique idempotency key.&lt;BR /&gt; # If you're unsure whether a particular payment succeeded, you can reattempt&lt;BR /&gt; # it with the same idempotency key without worrying about double charging&lt;BR /&gt; # the buyer.&lt;BR /&gt; "idempotency_key" =&amp;gt; uniqid()&lt;BR /&gt;);&lt;BR /&gt;# The SDK throws an exception if a Connect endpoint responds with anything besides&lt;BR /&gt;# a 200-level HTTP code. This block catches any exceptions that occur from the request.&lt;BR /&gt;try {&lt;BR /&gt; $result = $transactions_api-&amp;gt;charge($location-&amp;gt;getId(), $request_body);&lt;BR /&gt; echo "&amp;lt;pre&amp;gt;";&lt;BR /&gt; print_r($result);&lt;BR /&gt; echo "&amp;lt;/pre&amp;gt;";&lt;BR /&gt;} catch (\SquareConnect\ApiException $e) {&lt;BR /&gt; echo "Caught exception!&amp;lt;br/&amp;gt;";&lt;BR /&gt; print_r("&amp;lt;strong&amp;gt;Response body:&amp;lt;/strong&amp;gt;&amp;lt;br/&amp;gt;");&lt;BR /&gt; echo "&amp;lt;pre&amp;gt;"; var_dump($e-&amp;gt;getResponseBody()); echo "&amp;lt;/pre&amp;gt;";&lt;BR /&gt; echo "&amp;lt;br/&amp;gt;&amp;lt;strong&amp;gt;Response headers:&amp;lt;/strong&amp;gt;&amp;lt;br/&amp;gt;";&lt;BR /&gt; echo "&amp;lt;pre&amp;gt;"; var_dump($e-&amp;gt;getResponseHeaders()); echo "&amp;lt;/pre&amp;gt;";&lt;BR /&gt;}&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 10 Jun 2017 10:16:38 GMT</pubDate>
      <guid>https://community.squareup.com/t5/Archived-Discussions-Read-Only/PHP-code-always-ends-with-caught-exception/m-p/40152#M55568</guid>
      <dc:creator>JobChunk</dc:creator>
      <dc:date>2017-06-10T10:16:38Z</dc:date>
    </item>
    <item>
      <title>Re: PHP code always ends with caught exception</title>
      <link>https://community.squareup.com/t5/Archived-Discussions-Read-Only/PHP-code-always-ends-with-caught-exception/m-p/40153#M55569</link>
      <description>&lt;P&gt;Thanks i have fixed.. its working on localhost now.&lt;/P&gt;
&lt;P&gt;one thing more to confirm&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;can i run code on non ssl website for testing sandbox other then localhost?&lt;/P&gt;</description>
      <pubDate>Sat, 10 Jun 2017 10:36:42 GMT</pubDate>
      <guid>https://community.squareup.com/t5/Archived-Discussions-Read-Only/PHP-code-always-ends-with-caught-exception/m-p/40153#M55569</guid>
      <dc:creator>QaisarMalik</dc:creator>
      <dc:date>2017-06-10T10:36:42Z</dc:date>
    </item>
    <item>
      <title>Re: PHP code always ends with caught exception</title>
      <link>https://community.squareup.com/t5/Archived-Discussions-Read-Only/PHP-code-always-ends-with-caught-exception/m-p/40154#M55570</link>
      <description>&lt;P&gt;If you run it on a non-ssl url, you will see the same error as before.&lt;/P&gt;
&lt;P&gt;I figured out what was going on by expanding the error code to show everything.&lt;/P&gt;</description>
      <pubDate>Sat, 10 Jun 2017 11:01:01 GMT</pubDate>
      <guid>https://community.squareup.com/t5/Archived-Discussions-Read-Only/PHP-code-always-ends-with-caught-exception/m-p/40154#M55570</guid>
      <dc:creator>JobChunk</dc:creator>
      <dc:date>2017-06-10T11:01:01Z</dc:date>
    </item>
  </channel>
</rss>

