You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

216 regels
8.0 KiB

  1. import React from "react";
  2. import classNames from "classnames";
  3. import { makeStyles } from "@material-ui/core/styles";
  4. import Header from "components/Header/Header.js";
  5. import HeaderLinks from "components/Header/HeaderLinks.js";
  6. import Footer from "components/Footer/Footer.js";
  7. import OrderProduct from "pages-sections/yamaha/order/order.js";
  8. import Parallax from "components/Parallax/Parallax.js";
  9. import styles from "assets/jss/nextjs-material-kit/pages/components.js";
  10. import GetTransaction from "api/transaction/transaction.js";
  11. import Cookies from "cookies";
  12. import stylecss from "pages/home.css";
  13. const useStyles = makeStyles(styles);
  14. const Order = function ({ transactionToken, user, order, unpaid, prepared, sending, finished, backend, ...props }) {
  15. const classes = useStyles();
  16. const { ...rest } = props;
  17. return (
  18. <div>
  19. <Header
  20. leftLinks={<HeaderLinks username={user} />}
  21. fixed
  22. color="info"
  23. changeColorOnScroll={{
  24. height: 400,
  25. color: "white"
  26. }}
  27. {...rest}
  28. />
  29. <Parallax image={require("assets/img/Promotion_2-1.jpg")} width="200px"/>
  30. <div className={classNames(classes.main, classes.mainRaised)}>
  31. <OrderProduct order={order} transactionToken={transactionToken} unpaid={unpaid} prepared={prepared} sending={sending} finished={finished} backend={backend}/>
  32. <a href="https://wa.me/+6287797315685" class="float" target="_blank">
  33. <i class="fa fa-whatsapp my-float"></i>
  34. </a>
  35. </div>
  36. <Footer />
  37. </div>
  38. );
  39. }
  40. export default Order;
  41. export async function getServerSideProps(context) {
  42. var {query} = context;
  43. var order = [];
  44. var res = await GetTransaction.getTransaction();
  45. if (res["STATUS"] === 1) {
  46. order = res["DATA"]["transactions"];
  47. }
  48. console.log(order);
  49. var unpaid = [];
  50. var res = await GetTransaction.getTransactionUnpaid();
  51. if (res["STATUS"] === 1) {
  52. unpaid = res["DATA"]["transactions"];
  53. }
  54. var prepared = [];
  55. var res = await GetTransaction.getTransactionPrepared();
  56. if (res["STATUS"] === 1) {
  57. prepared = res["DATA"]["transactions"];
  58. }
  59. var sending = [];
  60. var res = await GetTransaction.getTransactionSending();
  61. if (res["STATUS"] === 1) {
  62. sending = res["DATA"]["transactions"];
  63. }
  64. var finished = [];
  65. var res = await GetTransaction.getTransactionFinished();
  66. if (res["STATUS"] === 1) {
  67. finished = res["DATA"]["transactions"];
  68. }
  69. //backend
  70. const backend = process.env.BACKEND_SERVER_URI;
  71. //user
  72. var { req, resp } = context;
  73. const cookies = new Cookies(req, resp);
  74. var user = "";
  75. var userObj = (await cookies.get("user"))
  76. ? JSON.parse(await cookies.get("user"))
  77. : null;
  78. if (userObj) {
  79. let sessionId = userObj["partners_login_states"].filter(function (i) {
  80. return (
  81. i.business_partner && i.business_partner.name.toUpperCase() == "YAMAHA"
  82. );
  83. });
  84. if (sessionId.length != 0) user = userObj["username"];
  85. }
  86. // midtrans
  87. var parameters = await GetTransaction.PayTransactionUnpaid();
  88. console.log("parameters", parameters);
  89. var transactionToken = [];
  90. if ( parameters["STATUS"] === 1 )
  91. {
  92. const midtransClient = require('midtrans-client');
  93. let snap = new midtransClient.Snap({
  94. isProduction : false,
  95. serverKey : 'SB-Mid-server-SfBhLkXXlTxCBx7EYP5T2k3d',
  96. clientKey : 'SB-Mid-client-srx674LjNbEybd4-'
  97. });
  98. let parameter = {
  99. "transaction_details": {
  100. "order_id": parameters["DATA"]["transactions"][0]["order_id"],
  101. "gross_amount": parameters["DATA"]["transactions"][0]["product_price"],
  102. // "order_id":"Trx-Ord-00000001",
  103. // "gross_amount":33750000,
  104. }, "credit_card":{
  105. "secure" : true
  106. },
  107. "customer_details": {
  108. "first_name": parameters["DATA"]["transactions"][0]["cust_name"],
  109. "phone": parameters["DATA"]["transactions"][0]["cust_telp"],
  110. // "first_name":"Yusmar",
  111. // "phone":"087797315685",
  112. "billing_address":
  113. {
  114. "first_name": parameters["DATA"]["transactions"][0]["cust_name"],
  115. "phone": parameters["DATA"]["transactions"][0]["cust_telp"],
  116. "address": parameters["DATA"]["transactions"][0]["cust_address"],
  117. // "first_name":"Yusmar",
  118. // "phone":"087797315685",
  119. // "address":"THAMRIN INDRAPURA JL.AIPDA KAREL SATSUIT TUBUN,17 ILIR, KEC.ILIR TIM.I, PALEMBANG, KOTA PALEMBANG - ILIR TIMUR II, SUMATERA SELATAN, ID 30114"
  120. },
  121. },
  122. };
  123. await snap.createTransaction(parameter)
  124. .then((transaction)=>{
  125. // transaction token
  126. transactionToken = transaction.token;
  127. console.log('transactionToken:',transactionToken);
  128. // transaction redirect url
  129. let transactionRedirectUrl = transaction.redirect_url;
  130. console.log('transactionRedirectUrl:',transactionRedirectUrl);
  131. })
  132. .catch((e)=>{
  133. console.log('Error occured:',e.message);
  134. });
  135. }
  136. // var transactionToken = [];
  137. // const midtransClient = require('midtrans-client');
  138. // let snap = new midtransClient.Snap({
  139. // isProduction : false,
  140. // serverKey : 'SB-Mid-server-SfBhLkXXlTxCBx7EYP5T2k3d',
  141. // clientKey : 'SB-Mid-client-srx674LjNbEybd4-'
  142. // });
  143. // let parameter = {
  144. // "transaction_details": {
  145. // // "order_id": parameters["DATA"]["transaction"]["id"],
  146. // // "gross_amount": parameters["DATA"]["transaction"]["product_price"],
  147. // "order_id":"Trx-Ord-00000001",
  148. // "gross_amount":33750000,
  149. // },
  150. // "credit_card": {
  151. // "secure" : true
  152. // },
  153. // "customer_details": {
  154. // // "first_name": parameters["DATA"]["transaction"]["cust_name"],
  155. // // "phone": parameters["DATA"]["transaction"]["cust_telp"],
  156. // "first_name":"Yusmar",
  157. // "phone":"087797315685",
  158. // "billing_address":
  159. // {
  160. // // "first_name": parameters["DATA"]["transaction"]["cust_name"],
  161. // // "phone": parameters["DATA"]["transaction"]["cust_telp"],
  162. // // "address": parameters["DATA"]["transaction"]["cust_address"],
  163. // "first_name":"Yusmar",
  164. // "phone":"087797315685",
  165. // "address":"THAMRIN INDRAPURA JL.AIPDA KAREL SATSUIT TUBUN,17 ILIR, KEC.ILIR TIM.I, PALEMBANG, KOTA PALEMBANG - ILIR TIMUR II, SUMATERA SELATAN, ID 30114"
  166. // },
  167. // "shipping_address":
  168. // {
  169. // // "first_name": parameters["DATA"]["transaction"]["cust_name"],
  170. // // "phone": parameters["DATA"]["transaction"]["cust_telp"],
  171. // // "address": parameters["DATA"]["transaction"]["cust_address"],
  172. // "first_name":"Yusmar",
  173. // "phone":"087797315685",
  174. // "address":"THAMRIN INDRAPURA JL.AIPDA KAREL SATSUIT TUBUN,17 ILIR, KEC.ILIR TIM.I, PALEMBANG, KOTA PALEMBANG - ILIR TIMUR II, SUMATERA SELATAN, ID 30114"
  175. // }
  176. // },
  177. // };
  178. // await snap.createTransaction(parameter)
  179. // .then((transaction)=> {
  180. // // transaction token
  181. // transactionToken = transaction.token;
  182. // console.log('transactionToken:',transactionToken);
  183. // // transaction redirect url
  184. // let transactionRedirectUrl = transaction.redirect_url;
  185. // console.log('transactionRedirectUrl:',transactionRedirectUrl);
  186. // })
  187. // .catch((e)=> {
  188. // console.log('Error occured:',e.message);
  189. // });
  190. console.log("token :", transactionToken);
  191. return {
  192. props: { backend, user, unpaid, prepared, sending, finished, order, transactionToken, }, // will be passed to the page component as props
  193. };
  194. }