From 6d7f0d66110fb91fa7c0fdf0b31a123c7f02ca88 Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Fri, 2 Oct 2015 11:32:13 +0300 Subject: [PATCH 1/6] Zapier fixes --- .../Controllers/AccountGatewayController.php | 6 +++++- app/Http/Controllers/IntegrationController.php | 9 +++++++-- app/Http/Controllers/PaymentController.php | 3 ++- app/Libraries/Utils.php | 18 +++++++++++++----- app/Models/Account.php | 1 + .../2014_07_24_171214_add_zapier_support.php | 1 - resources/views/header.blade.php | 3 +++ resources/views/master.blade.php | 15 +++++++++++++++ resources/views/public/license.blade.php | 1 + 9 files changed, 47 insertions(+), 10 deletions(-) diff --git a/app/Http/Controllers/AccountGatewayController.php b/app/Http/Controllers/AccountGatewayController.php index 2f53f9d486e2..dc55b08fc0d2 100644 --- a/app/Http/Controllers/AccountGatewayController.php +++ b/app/Http/Controllers/AccountGatewayController.php @@ -97,7 +97,11 @@ class AccountGatewayController extends BaseController $data['url'] = 'gateways'; $data['method'] = 'POST'; $data['title'] = trans('texts.add_gateway'); - $data['selectGateways'] = Gateway::where('payment_library_id', '=', 1)->where('id', '!=', GATEWAY_PAYPAL_EXPRESS)->where('id', '!=', GATEWAY_PAYPAL_EXPRESS)->orderBy('name')->get(); + $data['selectGateways'] = Gateway::where('payment_library_id', '=', 1) + ->where('id', '!=', GATEWAY_PAYPAL_EXPRESS) + ->where('id', '!=', GATEWAY_BITPAY) + ->where('id', '!=', GATEWAY_DWOLLA) + ->orderBy('name')->get(); $data['hiddenFields'] = Gateway::$hiddenFields; return View::make('accounts.account_gateway', $data); diff --git a/app/Http/Controllers/IntegrationController.php b/app/Http/Controllers/IntegrationController.php index de30afdfaf86..740c91e36127 100644 --- a/app/Http/Controllers/IntegrationController.php +++ b/app/Http/Controllers/IntegrationController.php @@ -13,10 +13,11 @@ class IntegrationController extends Controller $eventId = Utils::lookupEventId(trim(Input::get('event'))); if (!$eventId) { - return Response::json('', 500); + return Response::json('Event is invalid', 500); } - $subscription = Subscription::where('account_id', '=', Auth::user()->account_id)->where('event_id', '=', $eventId)->first(); + $subscription = Subscription::where('account_id', '=', Auth::user()->account_id) + ->where('event_id', '=', $eventId)->first(); if (!$subscription) { $subscription = new Subscription(); @@ -27,6 +28,10 @@ class IntegrationController extends Controller $subscription->target_url = trim(Input::get('target_url')); $subscription->save(); + if (!$subscription->id) { + return Response::json('Failed to create subscription', 500); + } + return Response::json('{"id":'.$subscription->id.'}', 201); } } diff --git a/app/Http/Controllers/PaymentController.php b/app/Http/Controllers/PaymentController.php index 0c64ef15b6dd..2a4eb331305f 100644 --- a/app/Http/Controllers/PaymentController.php +++ b/app/Http/Controllers/PaymentController.php @@ -368,7 +368,8 @@ class PaymentController extends BaseController 'message' => $affiliate->payment_subtitle, 'license' => $licenseKey, 'hideHeader' => true, - 'productId' => $license->product_id + 'productId' => $license->product_id, + 'price' => $affiliate->price, ]; $name = "{$license->first_name} {$license->last_name}"; diff --git a/app/Libraries/Utils.php b/app/Libraries/Utils.php index a04d08b25a2b..5221f61058de 100644 --- a/app/Libraries/Utils.php +++ b/app/Libraries/Utils.php @@ -599,9 +599,8 @@ class Utils public static function notifyZapier($subscription, $data) { $curl = curl_init(); - $jsonEncodedData = json_encode($data->toPublicArray()); - + $opts = [ CURLOPT_URL => $subscription->target_url, CURLOPT_RETURNTRANSFER => true, @@ -635,14 +634,23 @@ class Utils return $return; } - public static function hideIds($data) + public static function hideIds($data, $mapped = false) { $publicId = null; + if (!$mapped) { + $mapped = []; + } + foreach ($data as $key => $val) { if (is_array($val)) { - $data[$key] = Utils::hideIds($val); - } else if ($key == 'id' || strpos($key, '_id')) { + if ($key == 'account' || isset($mapped[$key])) { + unset($data[$key]); + } else { + $mapped[$key] = true; + $data[$key] = Utils::hideIds($val, $mapped); + } + } elseif ($key == 'id' || strpos($key, '_id')) { if ($key == 'public_id') { $publicId = $val; } diff --git a/app/Models/Account.php b/app/Models/Account.php index 6817275a8a99..adc365a612e7 100644 --- a/app/Models/Account.php +++ b/app/Models/Account.php @@ -13,6 +13,7 @@ class Account extends Eloquent { use SoftDeletes; protected $dates = ['deleted_at']; + protected $hidden = ['ip']; /* protected $casts = [ diff --git a/database/migrations/2014_07_24_171214_add_zapier_support.php b/database/migrations/2014_07_24_171214_add_zapier_support.php index b7bfc0a5bae3..3c8fbe69829f 100644 --- a/database/migrations/2014_07_24_171214_add_zapier_support.php +++ b/database/migrations/2014_07_24_171214_add_zapier_support.php @@ -24,7 +24,6 @@ class AddZapierSupport extends Migration { $table->string('target_url'); $table->foreign('account_id')->references('id')->on('accounts')->onDelete('cascade'); - $table->unique( ['account_id', 'event_id'] ); }); } diff --git a/resources/views/header.blade.php b/resources/views/header.blade.php index 8098a95808c4..28f37df03886 100644 --- a/resources/views/header.blade.php +++ b/resources/views/header.blade.php @@ -123,6 +123,7 @@ success: function(result) { if (result) { localStorage.setItem('guest_key', ''); + fbq('track', 'CompleteRegistration'); trackEvent('/account', '/signed_up'); NINJA.isRegistered = true; $('#signUpButton').hide(); @@ -164,6 +165,7 @@ NINJA.proPlanFeature = ''; function showProPlan(feature) { $('#proPlanModal').modal('show'); + fbq('track', 'InitiateCheckout'); trackEvent('/account', '/show_pro_plan/' + feature); NINJA.proPlanFeature = feature; } @@ -178,6 +180,7 @@ @if (Auth::check() && !Auth::user()->isPro()) function submitProPlan() { + fbq('track', 'AddPaymentInfo'); trackEvent('/account', '/submit_pro_plan/' + NINJA.proPlanFeature); if (NINJA.isRegistered) { $.ajax({ diff --git a/resources/views/master.blade.php b/resources/views/master.blade.php index 93fc0963553e..5ea7118c9241 100644 --- a/resources/views/master.blade.php +++ b/resources/views/master.blade.php @@ -63,6 +63,21 @@ + + + + +