surfboard_ttp 1.0.0
surfboard_ttp: ^1.0.0 copied to clipboard
Payments SDK for Surfboard Payments enabling payments for Flutter projects.
Surfboard TTP #
The SurfboardTTP enables payment services for your pos terminals.
SurfboardTTP SDK includes :
- Terminal - registration
- Order - creation, update, cancel
- Payment - initiation, status, cancel
To read more about Surfboard Payments, visit our website Surfboard Payments.
Getting Started #
The Stoked SDK enables payment services for your terminals. To initiate a payment, you can use the supported operations on the Stoked.
Add package to the pubspec.yaml as shown in the code below:
flutter pub add surfboard_ttp
Initialise the package #
Import the package using the snippet given below.
import'package:surfboard_ttp/surfboard_tt.dart'
To initialise the package, use the snippet given below
SurfboardTTP surfboardTTP = SurfboardTTP(
apiUrl: 'apiUrl',
terminalId: 'terminalId',
cpocBundleId: "bundleId",
partnerId: "partnerId",
merchantId: "merchantId",
storeId: "storeId",
appId: "appId");
As you can see in the above snippet, all the data are mandatory to initialise the SDK except terminalId which is obtained from terminal registration. If the terminal is already registered, you need to pass in the terminalId to avoid a trigger of the re-registration process.
Note: Make sure to initialise the SDK before using it in your application.
Set Authentication #
Sets the authToken generated by the authToken api. And this method has to be called every-time when the token is expired. To know more, visit Surfboard’s developer docs
surfboardTTP.setAuthToken(authToken: 'authToken');
Supported Operations on the SurfboardTTP #
Terminal Registration #
TerminalId is mandatory to perform order and payments, which is obtained by terminal registration of your pos app.
final Terminal terminal = Terminal();
1. Registering POS App #
Returns [RegisterTerminalReturnType] which contains the terminalId of the device and registrationCodeId and entryCode for the registration of cpoc app.
RegisterTerminalReturnType terminalReturn = await terminal.registerTerminal();
2. Launch CPOC for registration #
Launches the cpoc app for the registration against the merchant. The entryCode returned from [registerTerminal] has to be passed in this method. Cpoc app has to be installed to perfom the registration. Respective test and production pin app has to be downloaded and installed.
terminal.callCpocForRegistration("entryCode");
3. Registering CPOC againt POS #
Returns the terminalId of the cpoc. Once the cpoc switches back to your pos app, call this method to register the cpoc against your checkoutTerminal. The registrationCodeId from the [registerTerminal] has to be passed here
String cpocTerminalId = await.terminal.registerCpoc("registrationCodeId");
Performing Order operations #
After the terminal is registered, we are ready to create an order. An order instance can be created as given below.
Order order = Order(orderType: OrderType.purchaseOrder);
above order object takes OrderType parameter which can be either purchaseOrder or returnOrder .
1. Create Order #
To create an order, LineItem has to be added to the current order instance.
LineItem lineItem = LineItem(
id: '1234',
quantity: 1,
name: 'item1',
itemAmount: ItemAmount(
regular: 1000,
total: 1000,
currency: Currency.sek,
tax: [
Tax(
amount: 100,
percentage: 10,
type: TaxType.vat,
),
],
),
);
above is an example of a LineItem to be added to the order.
The lineItem has to be added by calling the addLineItem method and order can be created as below.
order.addLineItem(lineItem).createOrder();
2. Get Order Status #
Fetch the order status of the current order instance.
order.getOrderStatus();
3. Cancel Order #
Cancels the order and return the status against the current order instance.
order.cancelOrder();
Performing Payments #
Once order is created, payment can be done against that particular by passing its orderId.
Payment payment = Payment()
1. Initiate Payment #
The below code example can be used to initiate a payment for given orderId. Will launch the cpoc app for transaction after a successful payment initiation.
String paymentId = await payment.initiatePayment("orderId").paymentId;
2. Get Payment Status #
To check the payment status of the current payment instance. returns PaymentStatus .
PaymentStatus paymentStatus = await payment.getPaymentStatus();
3. Get Transaction Details #
Once the payment status is completed. call this method to the Transaction Details
TransactionDetails transactionDetails = await payment.getTransactionDetails();
This will return the transactionId , trancatedPan and other transactionDetails.
4. Cancel Payment #
Cancels the payment for the current payment instance and return PaymentStatus as cancelled .
Additional information #
To know more visit https://developers.surfboardpayments.com/docs