Arkademi Koin
Introduction
This document provides technical specifications for the Arkademi Koin on the Back End team side. Before reading this documentation, read here to understand basic information about Arkademi Koin.
Database Schema
For Arkademi Koin on the Back End side, data is managed by 2 data management, which are Firebase and MySQL.

Workflow

note
Adding Koin process in handled by Back End after the payment success (in charge to calculate the cashback amount from the price).
The Codes
Calculate The Price
../app/Api/V1/Controllers/Woocommerce/OrderController.php
if (isset($request["cashback"])) {
if ($koin == 0) {
$cashback = $price * 0.05;
}
}
AddCoins
if ($get->coin_price == 0 && $get->coupon_price == 0) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://asia-southeast2-arkademi-flutter-v201.cloudfunctions.net/v2/add-coins");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_POST, TRUE);
$params = '
{
"coins":' . $get->cashback . ',
"user_id":' . $get->user_id . '
}
';
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"Content-Type: application/json",
"Location: /api/v2/contract"
));
curl_exec($ch);
curl_close($ch);
}
Checking User's Koin
app/Api/V1/Controllers/Woocommerce/OrderController.php
$url = "https://asia-southeast2-arkademi-flutter-v201.cloudfunctions.net/v2/coin/" . $user_id . "";
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt(
$curl,
CURLOPT_HTTPHEADER,
array(
"Content-Type: application/json"
)
);
$result = curl_exec($curl);
$responses = json_decode($result, 1);
$coinChange[] = $responses['data']['coins'];
Add Coin to MySQL Database
app/Api/V1/Controllers/Woocommerce/OrderController.php
$arkademi_koin = abs($coinChange[0]);
curl_close($curl);
if ($total[2] <= $arkademi_koin) {
$koin = $total[2];
} else {
$koin = 0;
}
Create Order
app/Api/V1/Controllers/Woocommerce/OrderController.php
$object = NewOrder::create([
'product_id' => $product_id,
'user_id' => $user_id,
'payment_method' => $request['payment_method'],
'payment_method_title' => $request['payment_method_title'],
'customer_ip_address' => request()->ip(),
'customer_user_agent' => request()->userAgent(),
'created_via' => 'rest-api',
'billing_first_name' => $request['billing']['first_name'],
'billing_last_name' => $request['billing']['last_name'],
'billing_email' => $request['billing']['email'],
'billing_phone' => $request['billing']['phone'],
'order_currency' => 'IDR',
'code_coupon' => $code,
'coupon_price' => $discount,
'tax_price' => $tax_price ?? 0,
'sale_price' => $sale_price ?? 0,
'reguler_price' => $regular_price,
'diskon_price' => substr($kode_unik, 1),
'coin_price' => $koin,
'cashback' => $cashback ?? 0,
'order_total' => $order_total,
'order_status' => $request['status'],
'created_at' => Carbon::now()
]);
Created On: 25 May 2023
Written By: Media
Discussed With: Fauzan
Checked By: Fauzan