Harvest only the error message from the webhook endpoint

This commit is contained in:
David Bomba 2022-12-19 14:57:44 +11:00
parent 7fc794bfde
commit 9cb1e2b0b4
6 changed files with 27 additions and 14 deletions

View File

@ -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.

View File

@ -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;

View File

@ -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();

View File

@ -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 {

View File

@ -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)){

View File

@ -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]);
}
}