public final class PosSdk
extends java.lang.Object
The Point of Sale SDK lets you start the Square Point of Sale app to take transactions with the Square hardware.
PosClient posClient = PosSdk.createClient(context, CLIENT_ID);
ChargeRequest request = new ChargeRequest.Builder(550, CurrencyCode.USD)
.note("Super Burrito, no cilantro")
.enforceBusinessLocation(locationId)
.autoReturn(4, TimeUnit.SECONDS)
.requestMetadata("#329")
.restrictTenderTypesTo(ChargeRequest.TenderType.CARD)
.build();
try {
Intent chargeIntent = posClient.createChargeIntent(request);
activity.startActivityForResult(chargeIntent, CHARGE_REQUEST_CODE);
} catch (ActivityNotFoundException e) {
posClient.openPointOfSalePlayStoreListing();
}
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == CHARGE_REQUEST_CODE) {
if (data == null) {
// This happens if Point of Sale was uninstalled or crashed while we're waiting for a result.
return;
}
if (resultCode == Activity.RESULT_OK) {
onTransactionSuccess(posClient.parseChargeSuccess(data));
} else {
onTransactionError(posClient.parseChargeError(data));
}
}
}
Modifier and Type | Method and Description |
---|---|
static PosClient |
createClient(android.content.Context context,
java.lang.String clientId)
Creates a new instance of
PosClient that can then be used to create charge
intents. |
public static PosClient createClient(android.content.Context context, java.lang.String clientId)
PosClient
that can then be used to create charge
intents.context
- Any Context
will work. It is safe to pass in an activity context, as
the PosClient
instance will only hold on to the result from Context.getApplicationContext()
.clientId
- Client ID provided by Square.PosClient
instance.java.lang.NullPointerException
- if context or clientId are null.