From 71ee7523a35b6e12a8f27048fb597a9203e3cb58 Mon Sep 17 00:00:00 2001 From: Mo Firouz Date: Mon, 17 Jul 2017 07:53:41 +0100 Subject: [PATCH] Add RPC notification. Update IAP failure messages --- pkg/iap/apple.go | 2 +- pkg/iap/google.go | 10 +++++----- server/core_purchase.go | 4 ++-- tests/modules/notification.lua | 32 ++++++++++++++++++++++++++++++++ 4 files changed, 40 insertions(+), 8 deletions(-) create mode 100644 tests/modules/notification.lua diff --git a/pkg/iap/apple.go b/pkg/iap/apple.go index 8640eb777..4012e2b74 100644 --- a/pkg/iap/apple.go +++ b/pkg/iap/apple.go @@ -78,7 +78,7 @@ func NewAppleClientWithHTTP(password string, production bool, httpClient *http.C func (ac *AppleClient) init(production bool) error { if ac.password == "" { - return errors.New("Apple in-app purchase configuration is inactive. Reason: Missing password.") + return errors.New("Missing password.") } return nil diff --git a/pkg/iap/google.go b/pkg/iap/google.go index b2cfea91c..93debd0e7 100644 --- a/pkg/iap/google.go +++ b/pkg/iap/google.go @@ -48,20 +48,20 @@ func NewGoogleClient(packageName string, serviceKeyFilePath string, timeout int) } if gc.packageName == "" { - return nil, errors.New("Google in-app purchase configuration is inactive. Reason: Missing package name.") + return nil, errors.New("Missing package name.") } if gc.serviceKeyFilePath == "" { - return nil, errors.New("Google in-app purchase configuration is inactive. Reason: Missing service account key.") + return nil, errors.New("Missing service account key.") } jsonContent, err := ioutil.ReadFile(gc.serviceKeyFilePath) if err != nil { - return nil, errors.New("Google in-app purchase configuration is inactive. Reason: Failed to read Google service account key.") + return nil, errors.New("Failed to read Google service account key.") } config, err := google.JWTConfigFromJSON(jsonContent, GOOGLE_IAP_SCOPE) if err != nil { - return nil, errors.New("Google in-app purchase configuration is inactive. Reason: Failed to parse Google service account key.") + return nil, errors.New("Failed to parse Google service account key.") } gc.client = config.Client(context.Background()) @@ -71,7 +71,7 @@ func NewGoogleClient(packageName string, serviceKeyFilePath string, timeout int) func NewGoogleClientWithHTTP(packageName string, httpClient *http.Client) (*GoogleClient, error) { if packageName == "" { - return nil, errors.New("Google in-app purchase configuration is inactive. Reason: Missing package name.") + return nil, errors.New("Missing package name.") } gc := &GoogleClient{ diff --git a/server/core_purchase.go b/server/core_purchase.go index 41b5fe30a..c927cea38 100644 --- a/server/core_purchase.go +++ b/server/core_purchase.go @@ -36,7 +36,7 @@ type PurchaseService struct { func NewPurchaseService(jsonLogger *zap.Logger, multiLogger *zap.Logger, db *sql.DB, config *PurchaseConfig) *PurchaseService { ac, err := iap.NewAppleClient(config.Apple.Password, config.Apple.Production, config.Apple.TimeoutMs) if err != nil { - multiLogger.Warn("Skip initialising Apple in-app purchase provider", zap.Error(err)) + multiLogger.Warn("Skip initialising Apple in-app purchase provider", zap.String("reason,", err.Error())) } else { if config.Apple.Production { multiLogger.Info("Apple in-app purchase environment is set to Production priority.") @@ -48,7 +48,7 @@ func NewPurchaseService(jsonLogger *zap.Logger, multiLogger *zap.Logger, db *sql gc, err := iap.NewGoogleClient(config.Google.PackageName, config.Google.ServiceKeyFilePath, config.Google.TimeoutMs) if err != nil { - multiLogger.Warn("Skip initialising Google in-app purchase provider", zap.Error(err)) + multiLogger.Warn("Skip initialising Google in-app purchase provider", zap.String("reason", err.Error())) } return &PurchaseService{ diff --git a/tests/modules/notification.lua b/tests/modules/notification.lua new file mode 100644 index 000000000..8c6b94dce --- /dev/null +++ b/tests/modules/notification.lua @@ -0,0 +1,32 @@ +--[[ + Copyright 2017 The Nakama Authors + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--]] + +local nk = require("nakama") +local nx = require("nakamax") + +function notification_send(ctx, payload) + notifications = { + { Subject="test_notification",Content='{"hello": "world"}',UserId=ctx["user_id"],Code=101,Persistent=true }, + } + + local status, res = pcall(nk.notifications_send_id, notifications) + if not status then + print(res) + end + assert(status == true) +end + +nk.register_rpc(notification_send, "notification_send") -- GitLab