Skip to content

Commit

Permalink
Fix and update error messages for Stripe 'card' errors
Browse files Browse the repository at this point in the history
Now logs card failures as 'info' messages.
  • Loading branch information
Kjell M. Myksvoll committed Dec 4, 2019
1 parent 4f6b35b commit f5ead5a
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package org.ostelco.prime.customer.endpoint.store

import arrow.core.Either
import arrow.core.flatMap
import arrow.core.left
import org.ostelco.prime.activation.Activation
import org.ostelco.prime.apierror.ApiError
import org.ostelco.prime.apierror.ApiErrorCode
Expand Down Expand Up @@ -29,6 +30,7 @@ import org.ostelco.prime.model.Subscription
import org.ostelco.prime.model.withSimProfileStatusAsInstalled
import org.ostelco.prime.module.getResource
import org.ostelco.prime.paymentprocessor.PaymentProcessor
import org.ostelco.prime.paymentprocessor.core.CardError
import org.ostelco.prime.paymentprocessor.core.PlanAlredyPurchasedError
import org.ostelco.prime.paymentprocessor.core.ProductInfo
import org.ostelco.prime.paymentprocessor.core.SourceDetailsInfo
Expand Down Expand Up @@ -304,12 +306,15 @@ class SubscriberDAOImpl : SubscriberDAO {
saveCard).fold(
{ paymentError ->
when (paymentError) {
is PlanAlredyPurchasedError -> Either.left(mapPaymentErrorToApiError("Already subscribed to plan. ",
is CardError -> mapPaymentErrorToApiError("Payment source rejected. ",
ApiErrorCode.PAYMENT_SOURCE_REJECTED,
paymentError).left()
is PlanAlredyPurchasedError -> mapPaymentErrorToApiError("Already subscribed to plan. ",
ApiErrorCode.ALREADY_SUBSCRIBED_TO_PLAN,
paymentError))
else -> Either.left(mapPaymentErrorToApiError("Failed to purchase product. ",
paymentError).left()
else -> mapPaymentErrorToApiError("Failed to purchase product. ",
ApiErrorCode.FAILED_TO_PURCHASE_PRODUCT,
paymentError))
paymentError).left()
}
// if no error, check if this was a topup of empty account, in that case send activate
}, { productInfo ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1567,16 +1567,16 @@ object Neo4jStoreSingleton : GraphStore {
it
}.linkReversalActionToTransaction(transaction) {
paymentProcessor.removeInvoice(it.id)
logger.warn(NOTIFY_OPS_MARKER, """
Failed to pay invoice for customer ${customer.id}, invoice-id: ${it.id}.
logger.info(NOTIFY_OPS_MARKER, """
Payment of invoice ${it.id} failed for customer ${customer.id}.
Verify that the invoice has been deleted or voided in Stripe dashboard.
""".trimIndent())
}.bind()

/* Force immediate payment of the invoice. */
val (invoicePaymentInfo) = paymentProcessor.payInvoice(invoice.id)
.mapLeft {
logger.warn("Payment of invoice ${invoice.id} failed for customer ${customer.id}.")
logger.info("Charging for invoice ${invoice.id} for product $sku failed for customer ${customer.id}.")
/* Adds failed purchase to customer history. */
AuditLog.warn(customerId = customer.id,
message = "Failed to complete purchase of product $sku for ${formatMoney(price)} " +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ object Reporter {
event)
)
event.type == "payment_intent.payment_failed" -> logger.warn(
format("Failed to create payment ${intent.id} for ${currency(intent.amount, intent.currency)}",
format("Creating payment ${intent.id} of ${currency(intent.amount, intent.currency)} failed",
event)
)
event.type == "payment_intent.succeeded" -> logger.debug(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ object ApiErrorMapper {
/* Log level depends on the type of payment error. */
fun mapPaymentErrorToApiError(description: String, errorCode: ApiErrorCode, paymentError: PaymentError): ApiError {
if (paymentError is org.ostelco.prime.paymentprocessor.core.CardError) {
logger.warn("{}: {}, paymentError: {}", errorCode, description, asJson(paymentError))
logger.info("{}: {}, paymentError: {}", errorCode, description, asJson(paymentError))
} else {
logger.error("{}: {}, paymentError: {}", errorCode, description, asJson(paymentError))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ enum class ApiErrorCode {
FAILED_TO_SET_DEFAULT_PAYMENT_SOURCE,
FAILED_TO_FETCH_PAYMENT_SOURCES_LIST,
FAILED_TO_REMOVE_PAYMENT_SOURCE,
PAYMENT_SOURCE_REJECTED,

// payment monitor
FAILED_TO_CHECK_API_VERSION,
Expand Down

0 comments on commit f5ead5a

Please sign in to comment.