React Native SDK
Install
Download Tamara React Native SDK
Run command line TamaraSDK Module:
npm install
npm run example
cd example
npm start
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)
Pay without creating order
If you created an order from your backend, use the checkout URL to process the payment.
Checkout URL is a component and displays when passed in the URL.
Example: Import component
import { TamaraCheckoutURL } from 'react-native-tamara-sdk'
Use component
<TamaraCheckoutURL
checkoutURL={checkout_url}
successURL={success_url}
failURL={fail_url}
cancelURL={cancel_url}
onSuccess={() => {
//Payment has been made successfully
}}
onFail={() => {
//Payment has occurred an error
}}
onCancelURL={() => {
//Payment has been cancelled
}}
/>
Create and pay order
Before adding order's information, create an order by calling this method with referenceOrderId and description. RefId is your unique id of your order.
TamaraPayment.createOrder(referenceOrderId, description)
The following information is 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 details with its name, price, tax, discount quantity...etc:
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 (zero value is accepted)
TamaraPayment.setShippingAmount(shippingFee)
Set discount (optional):
TamaraPayment.setDiscount(discount, name)
Proceed to Tamara payment page using:
TamaraPayment.paymentOrder()
Order detail
Get order detail param mandatory: orderId
TamaraPayment.getOrderDetail(orderId)
Example: Import function
import { orderDetail } from 'react-native-tamara-sdk'
After get response json string and parse to json
const result = await orderDetail(orderId);
const data = JSON.parse(result)
Authorise order
Authorise order by call this method with orderId. param mandatory: orderId
TamaraPayment.authoriseOrder(orderId)
Example: Import function
import { authoriseOrder } from 'react-native-tamara-sdk'
Get response json string and parse to json
const result = await authoriseOrder(orderId)
const data = JSON.parse(result)
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: Import function
import { cancelOrder } from 'react-native-tamara-sdk'
Get response json string and parse to json
const result = await cancelOrder(JSON.stringify(jsonData))
const data = JSON.parse(result)
Update order reference
Update order reference by call this method with orderId and orderReference.
param mandatory: orderId, orderReference
TamaraPayment.updateOrderReference(orderId, orderReference)
Example: Import function
import { updateOrderReference } from 'react-native-tamara-sdk'
Get response json string and parse to json
const result = await updateOrderReference(orderId, orderReference)
const data = JSON.parse(result)
Capture a payment
Note: Need to call authorise order method before calling 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: Import function
import { capturePayment } from 'react-native-tamara-sdk'
Get response json string and parse to json
const result = await capturePayment(JSON.stringify(jsonData))
const data = JSON.parse(result)
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: Import function
import { refunds } from 'react-native-tamara-sdk'
Get response json string and parse to json
const result = await refunds(orderId, jsonData)
const data = JSON.parse(result)
Render Cart Widget
Render cart widget, reference by call this method with language, country, publicKey, amount. param mandatory: language, country, publicKey, amount
import { renderCartPage } from 'react-native-tamara-sdk'
renderCartPage(language, country, publicKey, amount)
Example: Import function
import { renderCartPage } from 'react-native-tamara-sdk'
Get response json string and parse to json
const result = await renderCartPage(language, country, publicKey, amount)
const data = JSON.parse(result)
Render Product Widget
Render product widget, reference by call this method with language, country, publicKey, amount. param mandatory: language, country, publicKey, amount
import { renderProduct } from 'react-native-tamara-sdk'
renderProduct(language, country, publicKey, amount)
Example: Import function
import { renderProduct } from 'react-native-tamara-sdk'
Get response json string and parse to json
const result = await renderProduct(language, country, publicKey, amount)
const data = JSON.parse(result)
Check Payment Options
Check payment option by call this method with orderId and jsonData. jsonData: use library convert class PaymentOptionsRequest to json (Gson)
TamaraPayment.paymentOptions(jsonData)
Example: Import function
import { paymentOptions } from 'react-native-tamara-sdk'
Get response json string and parse to json
const result = await await paymentOptions(JSON.stringify(jsonData))
const data = JSON.parse(result)
Updated about 1 month ago