private void OnUpdatePaymentMethodResponse(KnetikRestResponse response)
        {
            if (!string.IsNullOrEmpty(response.Error))
            {
                throw new KnetikException("Error calling UpdatePaymentMethod: " + response.Error);
            }

            UpdatePaymentMethodData = (PaymentMethodResource)KnetikClient.Deserialize(response.Content, typeof(PaymentMethodResource), response.Headers);
            KnetikLogger.LogResponse(mUpdatePaymentMethodStartTime, "UpdatePaymentMethod", string.Format("Response received successfully:\n{0}", UpdatePaymentMethodData));

            if (UpdatePaymentMethodComplete != null)
            {
                UpdatePaymentMethodComplete(response.ResponseCode, UpdatePaymentMethodData);
            }
        }
        public async Task <IActionResult> Update([FromRoute] Guid id, [FromBody] PaymentMethodResource paymentMethodResource)
        {
            if (paymentMethodResource == null)
            {
                paymentMethodResource = new PaymentMethodResource();
            }

            var paymentMethod = _mapper.Map <PaymentMethodResource, PaymentMethod>(paymentMethodResource);
            var result        = await _paymentMethodsService.UpdateAsync(id, paymentMethod);

            if (!result.Success)
            {
                return(BadRequest(result));
            }

            return(Ok(result));
        }
        /// <inheritdoc />
        /// <summary>
        /// Update an existing payment method for a user &lt;b&gt;Permissions Needed:&lt;/b&gt; PAYMENTS_ADMIN or owner
        /// </summary>
        /// <param name="userId">ID of the user for whom the payment method is being updated</param>
        /// <param name="id">ID of the payment method being updated</param>
        /// <param name="paymentMethod">The updated payment method data</param>
        public void UpdatePaymentMethod(int?userId, int?id, PaymentMethodResource paymentMethod)
        {
            // verify the required parameter 'userId' is set
            if (userId == null)
            {
                throw new KnetikException(400, "Missing required parameter 'userId' when calling UpdatePaymentMethod");
            }
            // verify the required parameter 'id' is set
            if (id == null)
            {
                throw new KnetikException(400, "Missing required parameter 'id' when calling UpdatePaymentMethod");
            }

            mWebCallEvent.WebPath = "/users/{user_id}/payment-methods/{id}";
            if (!string.IsNullOrEmpty(mWebCallEvent.WebPath))
            {
                mWebCallEvent.WebPath = mWebCallEvent.WebPath.Replace("{format}", "json");
            }
            mWebCallEvent.WebPath = mWebCallEvent.WebPath.Replace("{" + "user_id" + "}", KnetikClient.ParameterToString(userId));
            mWebCallEvent.WebPath = mWebCallEvent.WebPath.Replace("{" + "id" + "}", KnetikClient.ParameterToString(id));

            mWebCallEvent.HeaderParams.Clear();
            mWebCallEvent.QueryParams.Clear();
            mWebCallEvent.AuthSettings.Clear();
            mWebCallEvent.PostBody = null;

            mWebCallEvent.PostBody = KnetikClient.Serialize(paymentMethod); // http body (model) parameter

            // authentication settings
            mWebCallEvent.AuthSettings.Add("oauth2_client_credentials_grant");

            // authentication settings
            mWebCallEvent.AuthSettings.Add("oauth2_password_grant");

            // make the HTTP request
            mUpdatePaymentMethodStartTime = DateTime.Now;
            mWebCallEvent.Context         = mUpdatePaymentMethodResponseContext;
            mWebCallEvent.RequestType     = KnetikRequestType.PUT;

            KnetikLogger.LogRequest(mUpdatePaymentMethodStartTime, "UpdatePaymentMethod", "Sending server request...");
            KnetikGlobalEventSystem.Publish(mWebCallEvent);
        }