Introducing Square’s Register API and E-commerce API

Enabling developers to help sellers accept payments wherever their buyers are: in person and online

Written by Jianliang Zhao.

Have you ever looked at Square’s hardware offerings (maybe our newest EMV and NFC card reader) and thought, “I could build something amazing using that”? Historically, payments and hardware development were often associated with archaic and difficult to use technology. Today we are excited to launch Square’s Register and E-commerce APIs. Any developer can build an iOS app that takes payments from a swipe, dip, or tap. Developers can now also enable a website with online payments through Square.

Register API

The Square Register API lets you focus on what you do best: crafting an amazing point of sale experience for your sellers. We’ll take care of moving the money. With just two API calls, you tell us how much you’d like us to charge a customer and let Square Register do all the heavy lifting. Customers pay just like they’re used to at any other Square seller, and we’ll even text, email, or print a receipt on the seller’s behalf. Best of all, it supports all our hardware, including the Square Stand and the new Square Contactless + Chip Reader.

In your app make an API request:

[SCCAPIRequest requestWithCallbackURL:yourAppCallbackURL
                               amount:amountToCharge
                       userInfoString:dataWePassBackToYou
                           merchantID:nil
                                notes:descriptionOfCharge
                 supportedTenderTypes:SCCAPIRequestTenderTypeCard
                    clearsDefaultFees:NO
                                error:**&**error];
[SCCAPIConnection performRequest:request error:**&**error];

Square Register switches to the foreground and completes the payment on your behalf. Once that’s done, we’ll call your app back with the result.

E-commerce API

Now any developer can build solutions for their customers to take payments on a website using Square. Whether you’re getting started selling online with Square’s Online Store; you’re growing through Square’s integrations with E-commerce platforms like Bigcommerce, Weebly, and Ecwid; or now, you’re building a custom website, any business can scale online with Square payments. What’s more, with our E-commerce API, Square takes the hassle out of PCI compliance without interfering with the design or look and feel of your website or re-directing customers off-site.

Square’s JavaScript library uses a set of transparent, dynamically styled iframes to accept the sensitive cardholder information. This way cardholder data never touches your web site or servers. In exchange, it returns a single-use card nonce:

<script type="text/javascript" src="https://js.squareup.com/v2/paymentform">
</script>
<script>
**var** paymentForm **=** **new** SqPaymentForm({
  applicationId**:** 'your_app_id',
  inputClass**:** 'sq-input',
  cardNumber**:** { elementId**:** 'sq-card-number' },
  cvv**:** { elementId**:** 'sq-cvv' },
  expirationDate**:** { elementId**:** 'sq-expiration-date' },
  postalCode**:** { elementId**:** 'sq-postal-code' },
  callbacks**:** {
    cardNonceResponseReceived**:** **function**(errors, nonce, cardData) {
      *// your app code*
    }
  }
});
**function** requestCardNonce() { paymentForm.requestCardNonce(); }
</script>

<div id="sq-card-number"></div>
<div id="sq-cvv"></div>
<div id="sq-expiration-date"></div>
<div id="sq-postal-code"></div>

<button type="submit" onclick="requestCardNonce()">Submit</button>

(See the docs for a full working example).

Your server uses the card nonce and charges the buyer’s card.

$api = new \SquareConnect\Api\TransactionApi();
$transaction = $api->charge($accessToken, $locationId, [
  'amount_money' => ['amount' => 1337, 'currency' => 'USD'],
  'idempotency_key' => uniqid(),
  'card_nonce' => $cardNonce
])->getTransaction();

print_r($transaction);

Or you can store the card with a customer record to charge on an ongoing basis.

// Create the customer
$customer = $customerApi->createCustomer($accessToken, [
  'given_name' => 'Customer Name',
  'note' => "add a note"
])->getCustomer();

print_r($customer);

// Link the card
$card = $cardApi->createCustomerCard($accessToken, $customer->getId(), [
  'card_nonce' => $cardNonce,
  'cardholder_name' => 'Customer Name',
  'billing_address': [
    'postal_code' => '12345'
  ]
])->getCard();

print_r($card);

Bring it all together

With today’s launch of the Register and E-commerce APIs developers can build solutions that provide any seller with online and in-person payments, all powered by Square. When you use Square’s commerce platform, you are giving the seller a solution that results in a single, cohesive view of their entire business. Sellers can identify when customers are purchasing online, in-store, or across both. Using Square’s APIs and tools make it simple for sellers to better understand their customers’ buying trends and habits. Finally, because developers are leveraging Square’s platform, the seller can also benefit from everything that Square payments offers: transparent pricing, no monthly fees, support for challenging chargebacks, chargeback protection, great analytics, open APIs, as well as access to Square Capital and Square’s SaaS offerings.

Get started today by signing up for Square, reading the documentation, and creating an app. zhao-squareup (Jianliang Zhao) *zhao-squareup has 1 repository available. Follow their code on GitHub.*github.com

Table Of Contents