# React Native SDK

## How to use it
Include function:
* Init:
Initialize before using it:
```
TamaraSdk.initSdk(AUTH_TOKEN, API_URL, NOTIFICATION_WEB_HOOK_URL, PUBLIC_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.
```
TamaraSdk.createOrder(referenceOrderId, description)
```
### These informations are mandatory:

Set customer's information:
```
TamaraSdk.setCustomerInfo(firstName, lastName,
            phoneNumber, email, isFirstOrder)
```
Example:
import { setCustomerInfo} from 'react-native-tamara-sdk'
setCustomerInfo(textInputFirstName, textInputLastName, textInputPhone, textInputEmail, isChecked);
```

Set payment type (optional: default: PAY_BY_INSTALMENTS):
```
TamaraSdk.setPaymentType(paymentType)
```
Example:
import { setPaymentType} from 'react-native-tamara-sdk'
setPaymentType("PAY_BY_INSTALMENTS");
```

Add Item with its price, tax and discount:
```
TamaraSdk.addItem(name, referenceId ,sku, type, unitPrice,
                    taxAmount ,discountAmount, quantity)
```

Set shipping address and billing address:
```
TamaraSdk.setShippingAddress(firstName,lastName, phone,
                    addressLine1, addressLine2, country, region, city)
TamaraSdk.setBillingAddress(firstName,lastName, phone,
                    addressLine1, addressLine2, country, region, city)
```

Set shipping fee:
```
TamaraSdk.setShippingAmount(shippingFee)
```

Set discount (optional):
```
TamaraSdk.setDiscount(discount, name)
```

Set instalments:
```
TamaraSdk.setInstalments(instalments)
```
Set platform:
import { setPlatform } from 'react-native-tamara-sdk'
setPlatform("Android");//IOS
```

Set locale:
```
TamaraSdk.setLocale(locale)
```

Set order number:
```
TamaraSdk.setOrderNumber(orderNumber)
```

Set expires in minutes:
```
TamaraSdk.setExpiresInMinutes(expiresInMinutes)
```

Set risk assessment:
```
TamaraSdk.setRiskAssessment(jsonData)
```
Example:
import {setRiskAssessment} from 'react-native-tamara-sdk'
let result = await setRiskAssessment(jsonData); // return value true or false
if (result) {
  //json ok
}
```

Set additional data:
```
TamaraSdk.setAdditionalData(jsonData)
```

Add Custom Fields AdditionalData: 
Example val jsonData = "{\"custom_field1\": 42, \"custom_field2\": \"value2\" }"
```
TamaraSdk.addCustomFieldsAdditionalData(jsonData)
```
Example:
import { addCustomFieldsAdditionalData } from 'react-native-tamara-sdk'
addCustomFieldsAdditionalData("{\"custom_field1\": 42, \"custom_field2\": \"value2\" }");
```

Processes to Tamara payment page using:
```
TamaraSdk.paymentOrder()
```
Example: 
import {paymentOrder} from 'react-native-tamara-sdk';
const jsonString = await paymentOrder();
const result = JSON.parse(jsonString);
```
## Order detail
Get order detail
param mandatory: orderId
```
TamaraSdk.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
```
TamaraSdk.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)
```
TamaraSdk.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
```
TamaraSdk.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 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)
```
TamaraSdk.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)

```
TamaraSdk.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 widget checkout page
Render widget cart page reference by call this method with language, country, publicKey, amount.
param mandatory: language, country, publicKey, amount

```
TamaraSdk.renderWidgetCartPage(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 widget product
Render widget cart page reference by call this method with language, country, publicKey, amount.
param mandatory: language, country, publicKey, amount

```
TamaraSdk.renderWidgetProduct(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 available
Check payment option by call this method with orderId and jsonData.
jsonData: use library convert class PaymentOptions to json (Gson)
```
TamaraSdk.paymentOptions(jsonData)
```
Example:
Import function
```
import { checkPaymentOptions } from 'react-native-tamara-sdk'
```
Get response json string and parse to json
```
const result = await await checkPaymentOptions(JSON.stringify(jsonData))
const data = JSON.parse(result)
```

## Checkout URL
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={handleSuccess}
    onFail={handleFail}
    onCancel={handleCancel}
/>
```