lib/litle/models/litle_response.rb in killbill-litle-1.0.2 vs lib/litle/models/litle_response.rb in killbill-litle-1.0.3
- old
+ new
@@ -39,11 +39,13 @@
potential_litle_txn_id = params_litleonelineresponse_saleresponse_litle_txn_id || authorization
if potential_litle_txn_id.blank?
nil
else
# Litle seems to return the precision sometimes along with the txnId (e.g. 053499651324799+19)
- ("%f" % potential_litle_txn_id.split('+')[0]).to_i
+ # And sometimes it adds a ;credit
+ # TODO Figure out WTF is going on here
+ ("%f" % potential_litle_txn_id.split(';')[0].split('+')[0]).to_i
end
end
def self.from_response(api_call, kb_payment_id, response)
LitleResponse.new({
@@ -75,33 +77,42 @@
:success => response.success?
})
end
def to_payment_response
- to_killbill_response Killbill::Plugin::PaymentResponse
+ to_killbill_response :payment
end
def to_refund_response
- to_killbill_response Killbill::Plugin::RefundResponse
+ to_killbill_response :refund
end
private
- def to_killbill_response(klass)
+ def to_killbill_response(type)
if litle_transaction.nil?
amount_in_cents = nil
created_date = created_at
+ first_payment_reference_id = nil
+ second_payment_reference_id = nil
else
amount_in_cents = litle_transaction.amount_in_cents
created_date = litle_transaction.created_at
+ first_payment_reference_id = litle_transaction.litle_txn_id
+ second_payment_reference_id = litle_transaction.id.to_s
end
effective_date = params_litleonelineresponse_saleresponse_response_time || created_date
- status = message == 'Approved' ? Killbill::Plugin::PaymentStatus::SUCCESS : Killbill::Plugin::PaymentStatus::ERROR
- gateway_error = params_litleonelineresponse_saleresponse_message
+ gateway_error = message || params_litleonelineresponse_saleresponse_message
gateway_error_code = params_litleonelineresponse_saleresponse_response
- klass.new(amount_in_cents, created_date, effective_date, status, gateway_error, gateway_error_code)
+ if type == :payment
+ status = success ? Killbill::Plugin::Model::PaymentPluginStatus.new(:PROCESSED) : Killbill::Plugin::Model::PaymentPluginStatus.new(:ERROR)
+ Killbill::Plugin::Model::PaymentInfoPlugin.new(amount_in_cents, created_date, effective_date, status, gateway_error, gateway_error_code, first_payment_reference_id, second_payment_reference_id)
+ else
+ status = success ? Killbill::Plugin::Model::RefundPluginStatus.new(:PROCESSED) : Killbill::Plugin::Model::RefundPluginStatus.new(:ERROR)
+ Killbill::Plugin::Model::RefundInfoPlugin.new(amount_in_cents, created_date, effective_date, status, gateway_error, gateway_error_code, first_payment_reference_id)
+ end
end
def self.extract(response, key1, key2=nil, key3=nil)
return nil if response.nil? || response.params.nil?
level1 = response.params[key1]