tamara_flutter_sdk 1.0.1 tamara_flutter_sdk: ^1.0.1 copied to clipboard
Tamara Check out SDK
Integrate Tamara Checkout Flow into Flutter App
Features #
- Add callback for checkout flows:
- onPaymentSuccess
- onPaymentFailed
- onPaymentCanceled
Getting started #
Add sdk to your pubspec.yaml file
dependencies:
flutter:
sdk: flutter
tamara_sdk: ^0.9.1
Get URLs #
Your Back End must call our Api for generating:
- Checkout URL
- Success URL
- Failed URL
- Canceled URL
Usage #
Include TamaraCheckout in your Widget builder
Expanded(
child: TamaraCheckout(
checkoutUrl
successUrl,
failedUrl,
canceledUrl,
onPaymentSuccess: () {
_onPaymentSuccess();
},
onPaymentFailed: () {
_onPaymentFailed();
},
onPaymentCanceled: () {
_onPaymentCanceled();
},
)
);
##How to use it Include function:
- Init: Initialize before using it: TamaraPayment.initialize(AUTH_TOKEN, API_URL, NOTIFICATION_WEB_HOOK_URL, PUBLISH_KEY, NOTIFICATION_TOKEN, isSandbox)
Create and pay order #
Before adding order's information, create Order by call this method with referenceOrderId and description. RefId is your unique id of your order.
TamaraPayment.createOrder(referenceOrderId, description)
These informations are mandatory: #
Set customer's information:
TamaraPayment.setCustomerInfo(firstName, lastName,
phoneNumber, email, isFirstOrder)
Set payment type (optional: default: PAY_BY_INSTALMENTS):
TamaraPayment.setPaymentType(paymentType)
Add Item with its price, tax and discount:
TamaraPayment.addItem(name, referenceId ,sku, type, unitPrice,
taxAmount ,discountAmount, quantity)
Set shipping address and billing address:
TamaraPayment.setShippingAddress(firstName,lastName, phone,
addressLine1, addressLine2, country, region, city)
TamaraPayment.setBillingAddress(firstName,lastName, phone,
addressLine1, addressLine2, country, region, city)
Set shipping fee:
TamaraPayment.setShippingAmount(shippingFee)
Set discount (optional):
TamaraPayment.setDiscount(discount, name)
Processes to Tamara payment page using:
TamaraPayment.paymentOrder()
Order detail #
Get order detail param mandatory: orderId
TamaraPayment.getOrderDetail(orderId)
Example: Response: parse json data -> model String result = await TamaraSdk.getOrderDetail(orderId); final orderDetail = OrderDetail.fromJson(jsonDecode(result)); OrderDetail.fromJson(Map<String, dynamic> json) { billingAddress = json['billing_address'] != null ? BillingAddress.fromJson(json['billing_address']) : null; canceledAmount = json['canceled_amount'] != null ? CanceledAmount.fromJson(json['canceled_amount']) : null; capturedAmount = json['captured_amount'] != null ? CanceledAmount.fromJson(json['captured_amount']) : null; consumer = json['consumer'] != null ? Consumer.fromJson(json['consumer']) : null; countryCode = json['country_code']; createdAt = json['created_at']; description = json['description']; discountAmount = json['discount_amount'] != null ? CanceledAmount.fromJson(json['discount_amount']) : null; instalments = json['instalments']; if (json['items'] != null) { items =
Authorise order #
Authorise order by call this method with orderId. param mandatory: orderId
TamaraPayment.authoriseOrder(orderId)
Example: Response: String result = await TamaraSdk.authoriseOrder(orderId); final authoriseOrder = AuthoriseOrder.fromJson(jsonDecode(result)); AuthoriseOrder.fromJson(Map<String, dynamic> json) { autoCaptured = json['auto_captured']; orderExpiryTime = json['order_expiry_time']; orderId = json['order_id']; paymentType = json['payment_type']; status = json['status']; }
Cancel order #
Note: Need call authorise order method before call cancel order Cancel order reference by call this method with orderId and jsonData.
param mandatory: orderId jsonData: use library convert class CancelOrderRequest to json (Gson)
TamaraPayment.cancelOrder(orderId, jsonData)
Example: Response:
final cancelOrder = CancelOrder.fromJson(jsonDecode(result));
## Update order reference
Update order reference by call this method with orderId and orderReference.
param mandatory: orderId, orderReference
TamaraPayment.updateOrderReference(orderId, orderReference)
Example:
Response: final orderReference = OrderReference.fromJson(jsonDecode(result)); OrderReference.fromJson(Map<String, dynamic> json) { message = json['message']; }
## Capture a payment
Note: Need call authorise order method before call capture a payment
Cancel order reference by call this method with orderId and jsonData.
param mandatory: orderId
jsonData: use library convert class Capture to json (Gson)
TamaraPayment.getCapturePayment(jsonData)
Example:
Response:
TamaraSdk.getCapturePayment(jsonEncode(capture.toJson()));
Capture.fromJson(Map<String, dynamic> json) {
orderId = json['order_id'];
totalAmount = EAmount.fromJson(json['total_amount']);
taxAmount = EAmount.fromJson(json['tax_amount']);
shippingAmount = EAmount.fromJson(json['shipping_amount']);
discountAmount = EAmount.fromJson(json['discount_amount']);
if (json['items'] != null) {
items = <Item>[];
json['items'].forEach((itemJson) {
items!.add(Item.fromJson(itemJson));
});
}
shippingInfo = ShippingInfo.fromJson(json['shipping_info']);
}
## Refunds
Cancel order reference by call this method with orderId and jsonData.
Note: Need call authorise order method before call Refunds
param mandatory: orderId
jsonData: use library convert class Refund to json (Gson)
TamaraPayment.refunds(orderId, jsonData)
Example:
Response:
Refund refund = Refund(totalAmount: totalAmount, comment: comment);
final result = await TamaraSdk.refunds(orderId, jsonEncode(refund));
## Render widget cart page
Render widget cart page reference by call this method with language, country, publicKey, amount.
param mandatory: language, country, publicKey, amount
TamaraPayment.renderWidgetCartPage(language, country, publicKey, amount)
Example:
Response:
String result =
await TamaraSdk.renderCartPage(language, country, publicKey, amount);
final cartPage = CartPage.fromJson(jsonDecode(result));
CartPage.fromJson(Map<String, dynamic> json) {
script = json['script'];
url = json['url'];
}
## Render widget product
Render widget product reference by call this method with language, country, publicKey, amount.
param mandatory: language, country, publicKey, amount
TamaraPayment.renderWidgetProduct(language, country, publicKey, amount)
Example:
Response:
String result =
await TamaraSdk.renderProduct(language, country, publicKey, amount);
Product product = Product.fromJson(jsonDecode(result));
Product.fromJson(Map<String, dynamic> json) {
script = json['script'];
url = json['url'];
}