diff --git a/app/Http/Controllers/PurchaseOrderController.php b/app/Http/Controllers/PurchaseOrderController.php index 47cbcd68aeec..d08d51077c44 100644 --- a/app/Http/Controllers/PurchaseOrderController.php +++ b/app/Http/Controllers/PurchaseOrderController.php @@ -198,7 +198,7 @@ class PurchaseOrderController extends BaseController event(new PurchaseOrderWasCreated($purchase_order, $purchase_order->company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null))); - return $this->itemResponse($purchase_order); + return $this->itemResponse($purchase_order->fresh()); } /** * Display the specified resource. diff --git a/app/Http/Livewire/BillingPortalPurchasev2.php b/app/Http/Livewire/BillingPortalPurchasev2.php index 6215ded70193..429c45aeff36 100644 --- a/app/Http/Livewire/BillingPortalPurchasev2.php +++ b/app/Http/Livewire/BillingPortalPurchasev2.php @@ -179,7 +179,7 @@ class BillingPortalPurchasev2 extends Component $this->coupon = request()->query('coupon'); $this->handleCoupon(); } - elseif(strlen($this->subscription->promo_code) == 0 && $this->subscription->promo_discount > 0){ + elseif(isset($this->subscription->promo_code) && strlen($this->subscription->promo_code) == 0 && $this->subscription->promo_discount > 0){ $this->price = $this->subscription->promo_price; } @@ -226,6 +226,8 @@ class BillingPortalPurchasev2 extends Component public function resetEmail() { + $this->resetErrorBag('login'); + $this->resetValidation('login'); $this->email = null; } @@ -497,7 +499,7 @@ class BillingPortalPurchasev2 extends Component if(is_array($eligibility_check) && $eligibility_check['message'] != 'Success'){ $this->is_eligible = false; - $this->not_eligible_message =$eligibility_check['message']; + $this->not_eligible_message = $eligibility_check['message']; return $this; diff --git a/app/Services/PurchaseOrder/MarkSent.php b/app/Services/PurchaseOrder/MarkSent.php index 1450eefc1e41..4ea856ee7358 100644 --- a/app/Services/PurchaseOrder/MarkSent.php +++ b/app/Services/PurchaseOrder/MarkSent.php @@ -40,7 +40,7 @@ class MarkSent ->service() ->setStatus(PurchaseOrder::STATUS_SENT) ->applyNumber() - // ->adjustBalance($this->purchase_order->amount) + ->adjustBalance($this->purchase_order->amount) //why was this commented out previously? // ->touchPdf() ->save(); diff --git a/app/Services/PurchaseOrder/PurchaseOrderService.php b/app/Services/PurchaseOrder/PurchaseOrderService.php index 34a18e574894..4457006b908a 100644 --- a/app/Services/PurchaseOrder/PurchaseOrderService.php +++ b/app/Services/PurchaseOrder/PurchaseOrderService.php @@ -97,6 +97,13 @@ class PurchaseOrderService return $this; } + public function adjustBalance($adjustment) + { + $this->purchase_order->balance += $adjustment; + + return $this; + } + public function touchPdf($force = false) { try { diff --git a/app/Services/Subscription/SubscriptionService.php b/app/Services/Subscription/SubscriptionService.php index 0b06aeddddf3..8410dfe5a6bf 100644 --- a/app/Services/Subscription/SubscriptionService.php +++ b/app/Services/Subscription/SubscriptionService.php @@ -854,14 +854,11 @@ class SubscriptionService */ public function triggerWebhook($context) { - nlog("trigger webhook"); if (empty($this->subscription->webhook_configuration['post_purchase_url']) || is_null($this->subscription->webhook_configuration['post_purchase_url']) || strlen($this->subscription->webhook_configuration['post_purchase_url']) < 1) { return ["message" => "Success", "status_code" => 200]; } - nlog("past first if"); - $response = false; $body = array_merge($context, [ @@ -870,8 +867,6 @@ class SubscriptionService $response = $this->sendLoad($this->subscription, $body); - nlog("after response"); - /* Append the response to the system logger body */ if(is_array($response)){ diff --git a/app/Utils/Traits/SubscriptionHooker.php b/app/Utils/Traits/SubscriptionHooker.php index dc13aa491aaa..cd4d73a8525b 100644 --- a/app/Utils/Traits/SubscriptionHooker.php +++ b/app/Utils/Traits/SubscriptionHooker.php @@ -12,6 +12,8 @@ namespace App\Utils\Traits; use GuzzleHttp\RequestOptions; +use GuzzleHttp\Exception\ClientException; +use GuzzleHttp\Psr7\Message; /** * Class SubscriptionHooker. @@ -34,10 +36,6 @@ trait SubscriptionHooker 'headers' => $headers, ]); - nlog('method name must be a string'); - nlog($subscription->webhook_configuration['post_purchase_rest_method']); - nlog($subscription->webhook_configuration['post_purchase_url']); - $post_purchase_rest_method = (string) $subscription->webhook_configuration['post_purchase_rest_method']; $post_purchase_url = (string) $subscription->webhook_configuration['post_purchase_url']; @@ -47,7 +45,18 @@ trait SubscriptionHooker ]); return array_merge($body, json_decode($response->getBody(), true)); - } catch (\Exception $e) { + } catch (ClientException $e) { + + $message = $e->getMessage(); + + $error = json_decode($e->getResponse()->getBody()->getContents()); + + if(property_exists($error, 'message')) + $message = $error->message; + + return array_merge($body, ['message' => $message, 'status_code' => 500]); + } + catch (\Exception $e) { return array_merge($body, ['message' => $e->getMessage(), 'status_code' => 500]); } }