コード例 #1
0
        public void MarketPayAccountCreatedNotificationTest()
        {
            string json = GetFileContents("Mocks/marketpay/notification/account-created-success.json");
            NotificationHandler       notificationHandler = new NotificationHandler();
            IGenericNotification      notificationMessage = notificationHandler.HandleMarketpayNotificationJson(json);
            AccountCreateNotification accountCreateNotificationMessage = (AccountCreateNotification)notificationMessage;

            Assert.AreEqual("ACCOUNT_CREATED", accountCreateNotificationMessage.EventType);
            Assert.AreEqual("000", accountCreateNotificationMessage.Error.ErrorCode);
            Assert.AreEqual("test error message", accountCreateNotificationMessage.Error.Message);
            Assert.IsNotNull(accountCreateNotificationMessage.Content);

            CreateAccountResponse content = accountCreateNotificationMessage.Content;

            Assert.AreEqual("TestAccountHolder", content.AccountHolderCode);
            Assert.AreEqual("AC0000000001", content.AccountCode);
            Assert.AreEqual("account description", content.Description);
            Assert.AreEqual("MetaValue", content.Metadata["MetaKey"]);
            Assert.AreEqual(CreateAccountResponse.StatusEnum.Active, content.Status);

            PayoutScheduleResponse payoutSchedule = content.PayoutSchedule;

            Assert.AreEqual(PayoutScheduleResponse.ScheduleEnum.DAILY, payoutSchedule.Schedule);
            Assert.AreEqual(1, content.InvalidFields.Count);

            ErrorFieldType errorFieldType = content.InvalidFields[0];

            Assert.AreEqual(1, (long)errorFieldType.ErrorCode);
            Assert.AreEqual("Field is missing", errorFieldType.ErrorDescription);
            Assert.AreEqual("AccountHolderDetails.BusinessDetails.Shareholders.unknown", errorFieldType.FieldType.Field);
            Assert.AreEqual(FieldType.FieldNameEnum.Unknown, errorFieldType.FieldType.FieldName);
            Assert.AreEqual("SH00001", errorFieldType.FieldType.ShareholderCode);
        }
        public override object ReadJson(JsonReader reader,
                                        Type objectType, object existingValue,
                                        JsonSerializer serializer)
        {
            var jsonObject   = JObject.Load(reader);
            var notification = default(IGenericNotification);

            switch (jsonObject["eventType"].ToString())
            {
            case "ACCOUNT_CREATED":
                notification = new AccountCreateNotification();
                break;

            case "ACCOUNT_CLOSED":
                notification = new AccountCloseNotification();
                break;

            case "ACCOUNT_UPDATED":
                notification = new AccountUpdateNotification();
                break;

            case "ACCOUNT_FUNDS_BELOW_THRESHOLD":
                notification = new AccountFundsBelowThresholdNotification();
                break;

            case "ACCOUNT_HOLDER_CREATED":
                notification = new AccountHolderCreateNotification();
                break;

            case "ACCOUNT_HOLDER_VERIFICATION":
                notification = new AccountHolderVerificationNotification();
                break;

            case "ACCOUNT_HOLDER_STATUS_CHANGE":
                notification = new AccountHolderStatusChangeNotification();
                break;

            case "ACCOUNT_HOLDER_PAYOUT":
                notification = new AccountHolderPayoutNotification();
                break;

            case "ACCOUNT_HOLDER_UPDATED":
                notification = new AccountHolderUpdateNotification();
                break;

            case "ACCOUNT_HOLDER_STORE_STATUS_CHANGE":
                notification = new AccountHolderStoreStatusChangeNotification();
                break;

            case "ACCOUNT_HOLDER_UPCOMING_DEADLINE":
                notification = new AccountHolderUpcomingDeadlineNotification();
                break;

            case "BENEFICIARY_SETUP":
                notification = new BeneficiarySetupNotification();
                break;

            case "SCHEDULED_REFUNDS":
                notification = new ScheduledRefundsNotification();
                break;

            case "COMPENSATE_NEGATIVE_BALANCE":
                notification = new CompensateNegativeBalanceNotification();
                break;

            case "PAYMENT_FAILURE":
                notification = new PaymentFailureNotification();
                break;

            case "REPORT_AVAILABLE":
                notification = new ReportAvailableNotification();
                break;

            case "TRANSFER_FUNDS":
                notification = new TransferFundsNotification();
                break;

            case "DIRECT_DEBIT_INITIATED":
                notification = new DirectDebitInitiatedNotification();
                break;

            case "REFUND_FUNDS_TRANSFER":
                notification = new RefundFundsTransferNotification();
                break;
            }

            serializer.Populate(jsonObject.CreateReader(), notification);
            return(notification);
        }