@@ -222,12 +222,53 @@ class Registration
@customer.merchant_account,
@payment_method,
CONFIG[:activation_amount]
- ).then(&:insert).then {
+ ).then(
+ method(:sold),
+ ->(_) { declined }
+ )
+ end
+
+ protected
+
+ def sold(tx)
+ tx.insert.then {
@customer.bill_plan
}.then do
Finish.new(@iq, @customer, @tel).write
end
end
+
+ DECLINE_MESSAGE =
+ "Your bank declined the transaction. " \
+ "Often this happens when a person's credit card " \
+ "is a US card that does not support international " \
+ "transactions, as JMP is not based in the USA, though " \
+ "we do support transactions in USD.\n\n" \
+ "If you were trying a prepaid card, you may wish to use "\
+ "Privacy.com instead, as they do support international " \
+ "transactions.\n\n " \
+ "You may add another card and then choose next"
+
+ def decline_oob(reply)
+ oob = OOB.find_or_create(reply.command)
+ oob.url = CONFIG[:credit_card_url].call(
+ reply.to.stripped.to_s,
+ @customer.customer_id
+ )
+ oob.desc = DECLINE_MESSAGE
+ oob
+ end
+
+ def declined
+ reply = @iq.reply
+ reply_oob = decline_oob(reply)
+ reply.allowed_actions = [:next]
+ reply.note_type = :error
+ reply.note_text = "#{reply_oob.desc}: #{reply_oob.url}"
+ COMMAND_MANAGER.write(reply).then do |riq|
+ CreditCard.for(riq, @customer, @tel)
+ end
+ end
end
end
end
@@ -81,8 +81,12 @@ class Matching
end
class PromiseMock < Minitest::Mock
- def then- yield self
+ def then(succ=nil, _=nil)
+ if succ
+ succ.call(self)
+ else
+ yield self
+ end
end
end