Advertisement
wurtz

Update paymentIntent

May 14th, 2021
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1. public function updatePrices($newCost)
  2. {
  3. $this->subtotal += $newCost;
  4. $this->tax = round($this->subtotal * $this->tax_rate , 2);
  5. $this->total = $this->subtotal + $this->tax;
  6.  
  7. $secret_key = config('services.stripe.sk');
  8.  
  9. $stripe = new StripeClient(
  10. $secret_key
  11. );
  12.  
  13. $stripe->paymentIntents->update(
  14. $this->paymentIntentId,
  15. [
  16. 'amount' => $this->total * 100,
  17. ]
  18. );
  19.  
  20. $items = CartItem::where([
  21. ['user_id', $this->user_id],
  22. ['user_type', $this->user_type],
  23. ['use_case_id', $this->useCaseId],
  24. ['organization_id', $this->organization_id],
  25. ])->get();
  26.  
  27. $info = [];
  28.  
  29. foreach($items as $index => $item)
  30. {
  31. $info[$index] = [];
  32. $info[$index][0] = $item->item->name;
  33. $info[$index][1] = $item->qty;
  34.  
  35. $price = 0;
  36.  
  37. $options = CartItem::where('cart_item_id', $item->id)->get();
  38.  
  39. foreach($options as $option)
  40. {
  41. $price += $option->item->price;
  42. }
  43.  
  44. $info[$index][2] = $price + $item->item->price;
  45. }
  46.  
  47. $this->dispatchBrowserEvent('prices-updated', ['info' => $info]);
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement