<?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 Creating A New Customer and processing a transaction API V2 in Archived Discussions (Read Only)</title>
    <link>https://community.squareup.com/t5/Archived-Discussions-Read-Only/Creating-A-New-Customer-and-processing-a-transaction-API-V2/m-p/61073#M48887</link>
    <description>&lt;P&gt;I am using the v2 of the api and the transaction section seems to work fine without the creation of a customer.&lt;BR /&gt;&lt;BR /&gt;When i upt in the code to create a customer it seems to break.&lt;BR /&gt;&lt;BR /&gt;Please help.&lt;BR /&gt;&lt;BR /&gt;Code:&lt;BR /&gt;&lt;BR /&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 = 'sandbox-sq0atb-KFpTHy-EkAU-zmKIusEzug';&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; $capabilities = $location-&amp;gt;getCapabilities();&lt;BR /&gt; return is_array($capabilities) &amp;amp;&amp;amp;&lt;BR /&gt; in_array('CREDIT_CARD_PROCESSING', $capabilities);&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;$customer_api = new \SquareConnect\Api\CustomersApi();&lt;BR /&gt;$cust_obj = array(&lt;BR /&gt; 'given_name' =&amp;gt; 'Jeremy',&lt;BR /&gt; 'family_name'=&amp;gt; 'Test',&lt;BR /&gt; 'email_address' =&amp;gt; 'jeremy.moore@email.com',&lt;BR /&gt; 'phone_number'=&amp;gt; '250.555.5555'&lt;BR /&gt;);&lt;BR /&gt;$customer = $customer_api-&amp;gt;createCustomer($access_token, $cust_obj)-&amp;gt;getCustomer();&lt;BR /&gt;$transactions_api = new \SquareConnect\Api\TransactionsApi();&lt;BR /&gt;# To learn more about splitting transactions with additional recipients,&lt;BR /&gt;# see the Transactions API documentation on our [developer site]&lt;BR /&gt;# (&lt;A href="https://docs.connect.squareup.com/payments/transactions/overview#mpt-overview" target="_blank"&gt;https://docs.connect.squareup.com/payments/transactions/overview#mpt-overview&lt;/A&gt;).&lt;BR /&gt;$request_body = array (&lt;BR /&gt; "card_nonce" =&amp;gt; $nonce,&lt;BR /&gt; 'customer_id' =&amp;gt; $customer-&amp;gt;getId(),&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; "CAD"&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;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 05 Dec 2017 23:36:45 GMT</pubDate>
    <dc:creator>RestorInternati</dc:creator>
    <dc:date>2017-12-05T23:36:45Z</dc:date>
    <item>
      <title>Creating A New Customer and processing a transaction API V2</title>
      <link>https://community.squareup.com/t5/Archived-Discussions-Read-Only/Creating-A-New-Customer-and-processing-a-transaction-API-V2/m-p/61073#M48887</link>
      <description>&lt;P&gt;I am using the v2 of the api and the transaction section seems to work fine without the creation of a customer.&lt;BR /&gt;&lt;BR /&gt;When i upt in the code to create a customer it seems to break.&lt;BR /&gt;&lt;BR /&gt;Please help.&lt;BR /&gt;&lt;BR /&gt;Code:&lt;BR /&gt;&lt;BR /&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 = 'sandbox-sq0atb-KFpTHy-EkAU-zmKIusEzug';&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; $capabilities = $location-&amp;gt;getCapabilities();&lt;BR /&gt; return is_array($capabilities) &amp;amp;&amp;amp;&lt;BR /&gt; in_array('CREDIT_CARD_PROCESSING', $capabilities);&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;$customer_api = new \SquareConnect\Api\CustomersApi();&lt;BR /&gt;$cust_obj = array(&lt;BR /&gt; 'given_name' =&amp;gt; 'Jeremy',&lt;BR /&gt; 'family_name'=&amp;gt; 'Test',&lt;BR /&gt; 'email_address' =&amp;gt; 'jeremy.moore@email.com',&lt;BR /&gt; 'phone_number'=&amp;gt; '250.555.5555'&lt;BR /&gt;);&lt;BR /&gt;$customer = $customer_api-&amp;gt;createCustomer($access_token, $cust_obj)-&amp;gt;getCustomer();&lt;BR /&gt;$transactions_api = new \SquareConnect\Api\TransactionsApi();&lt;BR /&gt;# To learn more about splitting transactions with additional recipients,&lt;BR /&gt;# see the Transactions API documentation on our [developer site]&lt;BR /&gt;# (&lt;A href="https://docs.connect.squareup.com/payments/transactions/overview#mpt-overview" target="_blank"&gt;https://docs.connect.squareup.com/payments/transactions/overview#mpt-overview&lt;/A&gt;).&lt;BR /&gt;$request_body = array (&lt;BR /&gt; "card_nonce" =&amp;gt; $nonce,&lt;BR /&gt; 'customer_id' =&amp;gt; $customer-&amp;gt;getId(),&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; "CAD"&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;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 05 Dec 2017 23:36:45 GMT</pubDate>
      <guid>https://community.squareup.com/t5/Archived-Discussions-Read-Only/Creating-A-New-Customer-and-processing-a-transaction-API-V2/m-p/61073#M48887</guid>
      <dc:creator>RestorInternati</dc:creator>
      <dc:date>2017-12-05T23:36:45Z</dc:date>
    </item>
    <item>
      <title>Re: Creating A New Customer and processing a transaction API V2</title>
      <link>https://community.squareup.com/t5/Archived-Discussions-Read-Only/Creating-A-New-Customer-and-processing-a-transaction-API-V2/m-p/61557#M48888</link>
      <description>&lt;P&gt;Hello &lt;a href="https://community.squareup.com/t5/user/viewprofilepage/user-id/84440"&gt;@RestorInternati&lt;/a&gt;!&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;

&lt;P&gt;So we can look into this for you please&amp;nbsp;reply here with the exact error&amp;nbsp;you're receiving when you&amp;nbsp;try to create with a customer. We'll go from there!&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 08 Dec 2017 21:53:20 GMT</pubDate>
      <guid>https://community.squareup.com/t5/Archived-Discussions-Read-Only/Creating-A-New-Customer-and-processing-a-transaction-API-V2/m-p/61557#M48888</guid>
      <dc:creator>Helen</dc:creator>
      <dc:date>2017-12-08T21:53:20Z</dc:date>
    </item>
  </channel>
</rss>

