Guest User

Untitled

a guest
Oct 14th, 2019
69
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. sendToCart(merchantId) {
  2. this.showLoading();
  3. if (this.state.userId == '' || this.state.userId == null){
  4. Toast.info('Login terlebih dahulu');
  5. this.hideLoading();
  6. Actions.login();
  7. } else {
  8. axios({
  9. method: 'POST',
  10. url: Config.API_URL+'/api/vi/cart/add',
  11. headers: {
  12. Authorization: Config.TOKEN
  13. },
  14. data: {
  15. provider_auth:{
  16. token_auth: this.state.token_auth,
  17. token_type: this.state.token_type,
  18. },
  19. client_data:{
  20. product_merchant_id: merchantId,
  21. qty: 1,
  22. sales_quote_id: this.state.quote_id,
  23. customer_id: this.state.id
  24. }
  25. },
  26. timeout: 180000
  27. }).then((response) => {
  28. if (response.data.code == '200') {
  29. if (response.data.data.code == '200') {
  30. if (response.data.data.data.items == null) {
  31. Toast.fail('Mohon maaf untuk sementara produk belum dapat dibeli');
  32. this.hideLoading();
  33. } else {
  34. AsyncStorage.getItem('user', (error, result) => {
  35. if (result) {
  36. let asyncitem = JSON.parse(result);
  37. asyncitem.quote_id = response.data.data.data.quote;
  38. this.setState({
  39. quote_id: response.data.data.data.quote,
  40. });
  41. AsyncStorage.setItem('user', JSON.stringify(asyncitem), this.sendDetail(response.data.data.data.quote));
  42. }
  43. });
  44. }
  45. } else if (response.data.data.code == '400') {
  46. Toast.info('Produk gagal ditambahkan, terdapat produk non donasi atau produk donasi lainnya di keranjang');
  47. this.hideLoading();
  48. } else {
  49. Toast.fail('Mohon maaf untuk sementara produk belum dapat dibeli');
  50. this.hideLoading();
  51. }
  52. } else {
  53. Toast.fail('Mohon maaf untuk sementara produk belum dapat dibeli');
  54. this.hideLoading();
  55. }
  56. }).catch((error) => {
  57. this.hideLoading();
  58. Toast.fail('Terjadi gangguan, silahkan coba lagi!');
  59. });
  60. }
  61. };
RAW Paste Data