require 'spec_helper' ActiveMerchant::Billing::Base.mode = :test describe Killbill::Orbital::PaymentPlugin do include ::Killbill::Plugin::ActiveMerchant::RSpec before(:each) do # Start the plugin early to configure ActiveRecord @plugin = build_plugin(::Killbill::Orbital::PaymentPlugin, 'orbital') @plugin.start_plugin ::Killbill::Orbital::OrbitalPaymentMethod.delete_all ::Killbill::Orbital::OrbitalResponse.delete_all ::Killbill::Orbital::OrbitalTransaction.delete_all @call_context = build_call_context @properties = [] @pm = create_payment_method(::Killbill::Orbital::OrbitalPaymentMethod, nil, @call_context.tenant_id, @properties, { :cc_number => '5454545454545454' }) @amount = BigDecimal.new('100') @currency = 'USD' kb_payment_id = SecureRandom.uuid 1.upto(6) do @kb_payment = @plugin.kb_apis.proxied_services[:payment_api].add_payment(kb_payment_id) end end after(:each) do @plugin.stop_plugin end it 'should be able to charge a Credit Card directly' do account = @plugin.kb_apis.account_user_api.get_account_by_id(nil, @call_context) properties = build_pm_properties(account, { :cc_number => '5454545454545454' }) # We created the payment method, hence the rows Killbill::Orbital::OrbitalResponse.all.size.should == 1 Killbill::Orbital::OrbitalTransaction.all.size.should == 0 payment_response = @plugin.purchase_payment(@pm.kb_account_id, @kb_payment.id, @kb_payment.transactions[0].id, @pm.kb_payment_method_id, @amount, @currency, properties, @call_context) payment_response.status.should eq(:PROCESSED), payment_response.gateway_error payment_response.amount.should == @amount payment_response.transaction_type.should == :PURCHASE responses = Killbill::Orbital::OrbitalResponse.all responses.size.should == 2 responses[0].api_call.should == 'add_payment_method' responses[0].message.should == 'Profile Request Processed' responses[1].api_call.should == 'purchase' responses[1].message.should == 'Approved' transactions = Killbill::Orbital::OrbitalTransaction.all transactions.size.should == 1 transactions[0].api_call.should == 'purchase' end it 'should be able to charge and refund' do payment_response = @plugin.purchase_payment(@pm.kb_account_id, @kb_payment.id, @kb_payment.transactions[0].id, @pm.kb_payment_method_id, @amount, @currency, @properties, @call_context) payment_response.status.should eq(:PROCESSED), payment_response.gateway_error payment_response.amount.should == @amount payment_response.transaction_type.should == :PURCHASE # Try a full refund refund_response = @plugin.refund_payment(@pm.kb_account_id, @kb_payment.id, @kb_payment.transactions[1].id, @pm.kb_payment_method_id, @amount, @currency, @properties, @call_context) refund_response.status.should eq(:PROCESSED), refund_response.gateway_error refund_response.amount.should == @amount refund_response.transaction_type.should == :REFUND end it 'should be able to auth, capture and refund' do payment_response = @plugin.authorize_payment(@pm.kb_account_id, @kb_payment.id, @kb_payment.transactions[0].id, @pm.kb_payment_method_id, @amount, @currency, @properties, @call_context) payment_response.status.should eq(:PROCESSED), payment_response.gateway_error payment_response.amount.should == @amount payment_response.transaction_type.should == :AUTHORIZE # Try multiple partial captures partial_capture_amount = BigDecimal.new('10') 1.upto(3) do |i| payment_response = @plugin.capture_payment(@pm.kb_account_id, @kb_payment.id, @kb_payment.transactions[i].id, @pm.kb_payment_method_id, partial_capture_amount, @currency, @properties, @call_context) payment_response.status.should eq(:PROCESSED), payment_response.gateway_error payment_response.amount.should == partial_capture_amount payment_response.transaction_type.should == :CAPTURE end # Try a partial refund refund_response = @plugin.refund_payment(@pm.kb_account_id, @kb_payment.id, @kb_payment.transactions[4].id, @pm.kb_payment_method_id, partial_capture_amount, @currency, @properties, @call_context) refund_response.status.should eq(:PROCESSED), refund_response.gateway_error refund_response.amount.should == partial_capture_amount refund_response.transaction_type.should == :REFUND # Try to capture again payment_response = @plugin.capture_payment(@pm.kb_account_id, @kb_payment.id, @kb_payment.transactions[5].id, @pm.kb_payment_method_id, partial_capture_amount, @currency, @properties, @call_context) payment_response.status.should eq(:PROCESSED), payment_response.gateway_error payment_response.amount.should == partial_capture_amount payment_response.transaction_type.should == :CAPTURE end it 'should be able to auth and void' do payment_response = @plugin.authorize_payment(@pm.kb_account_id, @kb_payment.id, @kb_payment.transactions[0].id, @pm.kb_payment_method_id, @amount, @currency, @properties, @call_context) payment_response.status.should eq(:PROCESSED), payment_response.gateway_error payment_response.amount.should == @amount payment_response.transaction_type.should == :AUTHORIZE payment_response = @plugin.void_payment(@pm.kb_account_id, @kb_payment.id, @kb_payment.transactions[1].id, @pm.kb_payment_method_id, @properties, @call_context) payment_response.status.should eq(:PROCESSED), payment_response.gateway_error payment_response.transaction_type.should == :VOID end it 'should be able to auth, partial capture and void' do payment_response = @plugin.authorize_payment(@pm.kb_account_id, @kb_payment.id, @kb_payment.transactions[0].id, @pm.kb_payment_method_id, @amount, @currency, @properties, @call_context) payment_response.status.should eq(:PROCESSED), payment_response.gateway_error payment_response.amount.should == @amount payment_response.transaction_type.should == :AUTHORIZE partial_capture_amount = BigDecimal.new('10') payment_response = @plugin.capture_payment(@pm.kb_account_id, @kb_payment.id, @kb_payment.transactions[1].id, @pm.kb_payment_method_id, partial_capture_amount, @currency, @properties, @call_context) payment_response.status.should eq(:PROCESSED), payment_response.gateway_error payment_response.amount.should == partial_capture_amount payment_response.transaction_type.should == :CAPTURE payment_response = @plugin.void_payment(@pm.kb_account_id, @kb_payment.id, @kb_payment.transactions[2].id, @pm.kb_payment_method_id, @properties, @call_context) payment_response.status.should eq(:PROCESSED), payment_response.gateway_error payment_response.transaction_type.should == :VOID end end