spec/pesapal_merchant_spec.rb in pesapal-1.5.5 vs spec/pesapal_merchant_spec.rb in pesapal-1.5.6
- old
+ new
@@ -17,14 +17,11 @@
it 'sets default environment variable' do
expect(@pesapal.send(:env)).to eq 'development'
end
it 'sets default credentials' do
- expect(@pesapal.config).to eq({ :callback_url => 'http://0.0.0.0:3000/pesapal/callback',
- :consumer_key => '<YOUR_CONSUMER_KEY>',
- :consumer_secret => '<YOUR_CONSUMER_SECRET>'
- })
+ expect(@pesapal.config).to eq(default_credentials)
end
it 'sets default order details' do
expect(@pesapal.order_details).to eq({})
end
@@ -36,14 +33,11 @@
@pesapal.set_env
expect(@pesapal.send(:env)).to eq 'development'
end
it 'sets endpoints for default environment' do
- expect(@pesapal.set_env).to eq({:postpesapaldirectorderv4 => 'http://demo.pesapal.com/API/PostPesapalDirectOrderV4',
- :querypaymentstatus=>'http://demo.pesapal.com/API/QueryPaymentStatus',
- :querypaymentdetails=>'http://demo.pesapal.com/API/QueryPaymentDetails'
- })
+ expect(@pesapal.set_env).to eq(demo_endpoints)
end
end
describe '#generate_order_url' do
@@ -62,71 +56,74 @@
end
end
describe '#query_payment_status' do
+ before :each do
+ @request = stub_request(:get, /http:\/\/demo.pesapal.com\/API\/QueryPaymentStatus\?oauth_consumer_key=.*oauth_nonce=.*oauth_signature=.*oauth_signature_method=HMAC-SHA1&oauth_timestamp.*oauth_version=1.0&pesapal_merchant_reference=.*&pesapal_transaction_tracking_id=.*/)
+ end
+
it 'gets pending payment status' do
- stub_request(:get, /http:\/\/demo.pesapal.com\/API\/QueryPaymentStatus\?oauth_consumer_key=.*oauth_nonce=.*oauth_signature=.*oauth_signature_method=HMAC-SHA1&oauth_timestamp.*oauth_version=1.0&pesapal_merchant_reference=.*&pesapal_transaction_tracking_id=.*/).
- to_return(:status => 200, :body => 'pesapal_response_data=PENDING')
+ @request.to_return(:status => 200, :body => 'pesapal_response_data=PENDING')
expect(@pesapal.query_payment_status('merchant_reference', 'transaction_tracking_id')).to eq('PENDING')
end
it 'gets completed payment status' do
- stub_request(:get, /http:\/\/demo.pesapal.com\/API\/QueryPaymentStatus\?oauth_consumer_key=.*oauth_nonce=.*oauth_signature=.*oauth_signature_method=HMAC-SHA1&oauth_timestamp.*oauth_version=1.0&pesapal_merchant_reference=.*&pesapal_transaction_tracking_id=.*/).
- to_return(:status => 200, :body => 'pesapal_response_data=COMPLETED')
+ @request.to_return(:status => 200, :body => 'pesapal_response_data=COMPLETED')
expect(@pesapal.query_payment_status('merchant_reference', 'transaction_tracking_id')).to eq('COMPLETED')
end
it 'gets failed payment status' do
- stub_request(:get, /http:\/\/demo.pesapal.com\/API\/QueryPaymentStatus\?oauth_consumer_key=.*oauth_nonce=.*oauth_signature=.*oauth_signature_method=HMAC-SHA1&oauth_timestamp.*oauth_version=1.0&pesapal_merchant_reference=.*&pesapal_transaction_tracking_id=.*/).
- to_return(:status => 200, :body => 'pesapal_response_data=FAILED')
+ @request.to_return(:status => 200, :body => 'pesapal_response_data=FAILED')
expect(@pesapal.query_payment_status('merchant_reference', 'transaction_tracking_id')).to eq('FAILED')
end
it 'gets invalid payment status' do
- stub_request(:get, /http:\/\/demo.pesapal.com\/API\/QueryPaymentStatus\?oauth_consumer_key=.*oauth_nonce=.*oauth_signature=.*oauth_signature_method=HMAC-SHA1&oauth_timestamp.*oauth_version=1.0&pesapal_merchant_reference=.*&pesapal_transaction_tracking_id=.*/).
- to_return(:status => 200, :body => 'pesapal_response_data=INVALID')
+ @request.to_return(:status => 200, :body => 'pesapal_response_data=INVALID')
expect(@pesapal.query_payment_status('merchant_reference', 'transaction_tracking_id')).to eq('INVALID')
end
end
describe '#query_payment_details' do
+ before :each do
+ @request = stub_request(:get, /http:\/\/demo.pesapal.com\/API\/QueryPaymentDetails\?oauth_consumer_key=.*oauth_nonce=.*oauth_signature=.*oauth_signature_method=HMAC-SHA1&oauth_timestamp.*oauth_version=1.0&pesapal_merchant_reference=.*&pesapal_transaction_tracking_id=.*/)
+ end
+
it 'gets pending payment details' do
- stub_request(:get, /http:\/\/demo.pesapal.com\/API\/QueryPaymentDetails\?oauth_consumer_key=.*oauth_nonce=.*oauth_signature=.*oauth_signature_method=HMAC-SHA1&oauth_timestamp.*oauth_version=1.0&pesapal_merchant_reference=.*&pesapal_transaction_tracking_id=.*/).
- to_return(:status => 200, :body => 'pesapal_response_data=transaction_tracking_id,payment_method,payment_status,merchant_reference')
+ @request.to_return(:status => 200, :body => 'pesapal_response_data=transaction_tracking_id,payment_method,payment_status,merchant_reference')
expect(@pesapal.query_payment_details('merchant_reference', 'transaction_tracking_id')).to eq({ :method => 'payment_method',
:status => 'payment_status',
:merchant_reference => 'merchant_reference',
:transaction_tracking_id => 'transaction_tracking_id'
})
end
end
describe '#ipn_listener' do
+ before :each do
+ @request = stub_request(:get, /http:\/\/demo.pesapal.com\/API\/QueryPaymentStatus\?oauth_consumer_key=.*oauth_nonce=.*oauth_signature=.*oauth_signature_method=HMAC-SHA1&oauth_timestamp.*oauth_version=1.0&pesapal_merchant_reference=.*&pesapal_transaction_tracking_id=.*/)
+ end
+
it 'gets ipn response for pending status' do
- stub_request(:get, /http:\/\/demo.pesapal.com\/API\/QueryPaymentStatus\?oauth_consumer_key=.*oauth_nonce=.*oauth_signature=.*oauth_signature_method=HMAC-SHA1&oauth_timestamp.*oauth_version=1.0&pesapal_merchant_reference=.*&pesapal_transaction_tracking_id=.*/).
- to_return(:status => 200, :body => 'pesapal_response_data=PENDING')
+ @request.to_return(:status => 200, :body => 'pesapal_response_data=PENDING')
expect(@pesapal.ipn_listener('CHANGE', 'merchant_reference', 'transaction_tracking_id')).to eq({:status => 'PENDING', :response => nil})
end
it 'gets ipn response for completed status' do
- stub_request(:get, /http:\/\/demo.pesapal.com\/API\/QueryPaymentStatus\?oauth_consumer_key=.*oauth_nonce=.*oauth_signature=.*oauth_signature_method=HMAC-SHA1&oauth_timestamp.*oauth_version=1.0&pesapal_merchant_reference=.*&pesapal_transaction_tracking_id=.*/).
- to_return(:status => 200, :body => 'pesapal_response_data=COMPLETED')
+ @request.to_return(:status => 200, :body => 'pesapal_response_data=COMPLETED')
expect(@pesapal.ipn_listener('CHANGE', 'merchant_reference', 'transaction_tracking_id')).to eq({:status => 'COMPLETED', :response => 'pesapal_notification_type=CHANGE&pesapal_transaction_tracking_id=transaction_tracking_id&pesapal_merchant_reference=merchant_reference'})
end
it 'gets ipn response for failed status' do
- stub_request(:get, /http:\/\/demo.pesapal.com\/API\/QueryPaymentStatus\?oauth_consumer_key=.*oauth_nonce=.*oauth_signature=.*oauth_signature_method=HMAC-SHA1&oauth_timestamp.*oauth_version=1.0&pesapal_merchant_reference=.*&pesapal_transaction_tracking_id=.*/).
- to_return(:status => 200, :body => 'pesapal_response_data=FAILED')
+ @request.to_return(:status => 200, :body => 'pesapal_response_data=FAILED')
expect(@pesapal.ipn_listener('CHANGE', 'merchant_reference', 'transaction_tracking_id')).to eq({:status => 'FAILED', :response => 'pesapal_notification_type=CHANGE&pesapal_transaction_tracking_id=transaction_tracking_id&pesapal_merchant_reference=merchant_reference'})
end
it 'gets ipn response for invalid status' do
- stub_request(:get, /http:\/\/demo.pesapal.com\/API\/QueryPaymentStatus\?oauth_consumer_key=.*oauth_nonce=.*oauth_signature=.*oauth_signature_method=HMAC-SHA1&oauth_timestamp.*oauth_version=1.0&pesapal_merchant_reference=.*&pesapal_transaction_tracking_id=.*/).
- to_return(:status => 200, :body => 'pesapal_response_data=INVALID')
+ @request.to_return(:status => 200, :body => 'pesapal_response_data=INVALID')
expect(@pesapal.ipn_listener('CHANGE', 'merchant_reference', 'transaction_tracking_id')).to eq({:status => 'INVALID', :response => nil})
end
end
end
@@ -145,14 +142,11 @@
it 'sets environment variable' do
expect(@pesapal.send(:env)).to eq 'development'
end
it 'sets credentials' do
- expect(@pesapal.config).to eq({ :callback_url => 'http://0.0.0.0:3000/pesapal/callback',
- :consumer_key => '<YOUR_CONSUMER_KEY>',
- :consumer_secret => '<YOUR_CONSUMER_SECRET>'
- })
+ expect(@pesapal.config).to eq(default_credentials)
end
it 'sets order details' do
expect(@pesapal.order_details).to eq({})
end
@@ -164,14 +158,11 @@
@pesapal.set_env :development
expect(@pesapal.send(:env)).to eq 'development'
end
it 'sets endpoints for environment' do
- expect(@pesapal.set_env :development).to eq({:postpesapaldirectorderv4 => 'http://demo.pesapal.com/API/PostPesapalDirectOrderV4',
- :querypaymentstatus=>'http://demo.pesapal.com/API/QueryPaymentStatus',
- :querypaymentdetails=>'http://demo.pesapal.com/API/QueryPaymentDetails'
- })
+ expect(@pesapal.set_env :development).to eq(demo_endpoints)
end
end
describe '#generate_order_url' do
@@ -190,71 +181,74 @@
end
end
describe '#query_payment_status' do
+ before :each do
+ @request = stub_request(:get, /http:\/\/demo.pesapal.com\/API\/QueryPaymentStatus\?oauth_consumer_key=.*oauth_nonce=.*oauth_signature=.*oauth_signature_method=HMAC-SHA1&oauth_timestamp.*oauth_version=1.0&pesapal_merchant_reference=.*&pesapal_transaction_tracking_id=.*/)
+ end
+
it 'gets pending payment status' do
- stub_request(:get, /http:\/\/demo.pesapal.com\/API\/QueryPaymentStatus\?oauth_consumer_key=.*oauth_nonce=.*oauth_signature=.*oauth_signature_method=HMAC-SHA1&oauth_timestamp.*oauth_version=1.0&pesapal_merchant_reference=.*&pesapal_transaction_tracking_id=.*/).
- to_return(:status => 200, :body => 'pesapal_response_data=PENDING')
+ @request.to_return(:status => 200, :body => 'pesapal_response_data=PENDING')
expect(@pesapal.query_payment_status('merchant_reference', 'transaction_tracking_id')).to eq('PENDING')
end
it 'gets completed payment status' do
- stub_request(:get, /http:\/\/demo.pesapal.com\/API\/QueryPaymentStatus\?oauth_consumer_key=.*oauth_nonce=.*oauth_signature=.*oauth_signature_method=HMAC-SHA1&oauth_timestamp.*oauth_version=1.0&pesapal_merchant_reference=.*&pesapal_transaction_tracking_id=.*/).
- to_return(:status => 200, :body => 'pesapal_response_data=COMPLETED')
+ @request.to_return(:status => 200, :body => 'pesapal_response_data=COMPLETED')
expect(@pesapal.query_payment_status('merchant_reference', 'transaction_tracking_id')).to eq('COMPLETED')
end
it 'gets failed payment status' do
- stub_request(:get, /http:\/\/demo.pesapal.com\/API\/QueryPaymentStatus\?oauth_consumer_key=.*oauth_nonce=.*oauth_signature=.*oauth_signature_method=HMAC-SHA1&oauth_timestamp.*oauth_version=1.0&pesapal_merchant_reference=.*&pesapal_transaction_tracking_id=.*/).
- to_return(:status => 200, :body => 'pesapal_response_data=FAILED')
+ @request.to_return(:status => 200, :body => 'pesapal_response_data=FAILED')
expect(@pesapal.query_payment_status('merchant_reference', 'transaction_tracking_id')).to eq('FAILED')
end
it 'gets invalid payment status' do
- stub_request(:get, /http:\/\/demo.pesapal.com\/API\/QueryPaymentStatus\?oauth_consumer_key=.*oauth_nonce=.*oauth_signature=.*oauth_signature_method=HMAC-SHA1&oauth_timestamp.*oauth_version=1.0&pesapal_merchant_reference=.*&pesapal_transaction_tracking_id=.*/).
- to_return(:status => 200, :body => 'pesapal_response_data=INVALID')
+ @request.to_return(:status => 200, :body => 'pesapal_response_data=INVALID')
expect(@pesapal.query_payment_status('merchant_reference', 'transaction_tracking_id')).to eq('INVALID')
end
end
describe '#query_payment_details' do
+ before :each do
+ @request = stub_request(:get, /http:\/\/demo.pesapal.com\/API\/QueryPaymentDetails\?oauth_consumer_key=.*oauth_nonce=.*oauth_signature=.*oauth_signature_method=HMAC-SHA1&oauth_timestamp.*oauth_version=1.0&pesapal_merchant_reference=.*&pesapal_transaction_tracking_id=.*/)
+ end
+
it 'gets pending payment details' do
- stub_request(:get, /http:\/\/demo.pesapal.com\/API\/QueryPaymentDetails\?oauth_consumer_key=.*oauth_nonce=.*oauth_signature=.*oauth_signature_method=HMAC-SHA1&oauth_timestamp.*oauth_version=1.0&pesapal_merchant_reference=.*&pesapal_transaction_tracking_id=.*/).
- to_return(:status => 200, :body => 'pesapal_response_data=transaction_tracking_id,payment_method,payment_status,merchant_reference')
+ @request.to_return(:status => 200, :body => 'pesapal_response_data=transaction_tracking_id,payment_method,payment_status,merchant_reference')
expect(@pesapal.query_payment_details('merchant_reference', 'transaction_tracking_id')).to eq({ :method => 'payment_method',
:status => 'payment_status',
:merchant_reference => 'merchant_reference',
:transaction_tracking_id => 'transaction_tracking_id'
})
end
end
describe '#ipn_listener' do
+ before :each do
+ @request = stub_request(:get, /http:\/\/demo.pesapal.com\/API\/QueryPaymentStatus\?oauth_consumer_key=.*oauth_nonce=.*oauth_signature=.*oauth_signature_method=HMAC-SHA1&oauth_timestamp.*oauth_version=1.0&pesapal_merchant_reference=.*&pesapal_transaction_tracking_id=.*/)
+ end
+
it 'gets ipn response for pending status' do
- stub_request(:get, /http:\/\/demo.pesapal.com\/API\/QueryPaymentStatus\?oauth_consumer_key=.*oauth_nonce=.*oauth_signature=.*oauth_signature_method=HMAC-SHA1&oauth_timestamp.*oauth_version=1.0&pesapal_merchant_reference=.*&pesapal_transaction_tracking_id=.*/).
- to_return(:status => 200, :body => 'pesapal_response_data=PENDING')
+ @request.to_return(:status => 200, :body => 'pesapal_response_data=PENDING')
expect(@pesapal.ipn_listener('CHANGE', 'merchant_reference', 'transaction_tracking_id')).to eq({:status => 'PENDING', :response => nil})
end
it 'gets ipn response for completed status' do
- stub_request(:get, /http:\/\/demo.pesapal.com\/API\/QueryPaymentStatus\?oauth_consumer_key=.*oauth_nonce=.*oauth_signature=.*oauth_signature_method=HMAC-SHA1&oauth_timestamp.*oauth_version=1.0&pesapal_merchant_reference=.*&pesapal_transaction_tracking_id=.*/).
- to_return(:status => 200, :body => 'pesapal_response_data=COMPLETED')
+ @request.to_return(:status => 200, :body => 'pesapal_response_data=COMPLETED')
expect(@pesapal.ipn_listener('CHANGE', 'merchant_reference', 'transaction_tracking_id')).to eq({:status => 'COMPLETED', :response => 'pesapal_notification_type=CHANGE&pesapal_transaction_tracking_id=transaction_tracking_id&pesapal_merchant_reference=merchant_reference'})
end
it 'gets ipn response for failed status' do
- stub_request(:get, /http:\/\/demo.pesapal.com\/API\/QueryPaymentStatus\?oauth_consumer_key=.*oauth_nonce=.*oauth_signature=.*oauth_signature_method=HMAC-SHA1&oauth_timestamp.*oauth_version=1.0&pesapal_merchant_reference=.*&pesapal_transaction_tracking_id=.*/).
- to_return(:status => 200, :body => 'pesapal_response_data=FAILED')
+ @request.to_return(:status => 200, :body => 'pesapal_response_data=FAILED')
expect(@pesapal.ipn_listener('CHANGE', 'merchant_reference', 'transaction_tracking_id')).to eq({:status => 'FAILED', :response => 'pesapal_notification_type=CHANGE&pesapal_transaction_tracking_id=transaction_tracking_id&pesapal_merchant_reference=merchant_reference'})
end
it 'gets ipn response for invalid status' do
- stub_request(:get, /http:\/\/demo.pesapal.com\/API\/QueryPaymentStatus\?oauth_consumer_key=.*oauth_nonce=.*oauth_signature=.*oauth_signature_method=HMAC-SHA1&oauth_timestamp.*oauth_version=1.0&pesapal_merchant_reference=.*&pesapal_transaction_tracking_id=.*/).
- to_return(:status => 200, :body => 'pesapal_response_data=INVALID')
+ @request.to_return(:status => 200, :body => 'pesapal_response_data=INVALID')
expect(@pesapal.ipn_listener('CHANGE', 'merchant_reference', 'transaction_tracking_id')).to eq({:status => 'INVALID', :response => nil})
end
end
end
@@ -273,14 +267,11 @@
it 'sets environment variable' do
expect(@pesapal.send(:env)).to eq 'production'
end
it 'sets credentials' do
- expect(@pesapal.config).to eq({ :callback_url => 'http://0.0.0.0:3000/pesapal/callback',
- :consumer_key => '<YOUR_CONSUMER_KEY>',
- :consumer_secret => '<YOUR_CONSUMER_SECRET>'
- })
+ expect(@pesapal.config).to eq(default_credentials)
end
it 'sets order details' do
expect(@pesapal.order_details).to eq({})
end
@@ -292,14 +283,11 @@
@pesapal.set_env :production
expect(@pesapal.send(:env)).to eq 'production'
end
it 'sets endpoints for environment' do
- expect(@pesapal.set_env :production).to eq({:postpesapaldirectorderv4 => 'https://www.pesapal.com/API/PostPesapalDirectOrderV4',
- :querypaymentstatus=>'https://www.pesapal.com/API/QueryPaymentStatus',
- :querypaymentdetails=>'https://www.pesapal.com/API/QueryPaymentDetails'
- })
+ expect(@pesapal.set_env :production).to eq(production_endpoints)
end
end
describe '#generate_order_url' do
@@ -318,71 +306,97 @@
end
end
describe '#query_payment_status' do
+ before :each do
+ @request = stub_request(:get, /https:\/\/www.pesapal.com\/API\/QueryPaymentStatus\?oauth_consumer_key=.*oauth_nonce=.*oauth_signature=.*oauth_signature_method=HMAC-SHA1&oauth_timestamp.*oauth_version=1.0&pesapal_merchant_reference=.*&pesapal_transaction_tracking_id=.*/)
+ end
+
it 'gets pending payment status' do
- stub_request(:get, /https:\/\/www.pesapal.com\/API\/QueryPaymentStatus\?oauth_consumer_key=.*oauth_nonce=.*oauth_signature=.*oauth_signature_method=HMAC-SHA1&oauth_timestamp.*oauth_version=1.0&pesapal_merchant_reference=.*&pesapal_transaction_tracking_id=.*/).
- to_return(:status => 200, :body => 'pesapal_response_data=PENDING')
+ @request.to_return(:status => 200, :body => 'pesapal_response_data=PENDING')
expect(@pesapal.query_payment_status('merchant_reference', 'transaction_tracking_id')).to eq('PENDING')
end
it 'gets completed payment status' do
- stub_request(:get, /https:\/\/www.pesapal.com\/API\/QueryPaymentStatus\?oauth_consumer_key=.*oauth_nonce=.*oauth_signature=.*oauth_signature_method=HMAC-SHA1&oauth_timestamp.*oauth_version=1.0&pesapal_merchant_reference=.*&pesapal_transaction_tracking_id=.*/).
- to_return(:status => 200, :body => 'pesapal_response_data=COMPLETED')
+ @request.to_return(:status => 200, :body => 'pesapal_response_data=COMPLETED')
expect(@pesapal.query_payment_status('merchant_reference', 'transaction_tracking_id')).to eq('COMPLETED')
end
it 'gets failed payment status' do
- stub_request(:get, /https:\/\/www.pesapal.com\/API\/QueryPaymentStatus\?oauth_consumer_key=.*oauth_nonce=.*oauth_signature=.*oauth_signature_method=HMAC-SHA1&oauth_timestamp.*oauth_version=1.0&pesapal_merchant_reference=.*&pesapal_transaction_tracking_id=.*/).
- to_return(:status => 200, :body => 'pesapal_response_data=FAILED')
+ @request.to_return(:status => 200, :body => 'pesapal_response_data=FAILED')
expect(@pesapal.query_payment_status('merchant_reference', 'transaction_tracking_id')).to eq('FAILED')
end
it 'gets invalid payment status' do
- stub_request(:get, /https:\/\/www.pesapal.com\/API\/QueryPaymentStatus\?oauth_consumer_key=.*oauth_nonce=.*oauth_signature=.*oauth_signature_method=HMAC-SHA1&oauth_timestamp.*oauth_version=1.0&pesapal_merchant_reference=.*&pesapal_transaction_tracking_id=.*/).
- to_return(:status => 200, :body => 'pesapal_response_data=INVALID')
+ @request.to_return(:status => 200, :body => 'pesapal_response_data=INVALID')
expect(@pesapal.query_payment_status('merchant_reference', 'transaction_tracking_id')).to eq('INVALID')
end
end
describe '#query_payment_details' do
+ before :each do
+ @request = stub_request(:get, /https:\/\/www.pesapal.com\/API\/QueryPaymentDetails\?oauth_consumer_key=.*oauth_nonce=.*oauth_signature=.*oauth_signature_method=HMAC-SHA1&oauth_timestamp.*oauth_version=1.0&pesapal_merchant_reference=.*&pesapal_transaction_tracking_id=.*/)
+ end
+
it 'gets pending payment details' do
- stub_request(:get, /https:\/\/www.pesapal.com\/API\/QueryPaymentDetails\?oauth_consumer_key=.*oauth_nonce=.*oauth_signature=.*oauth_signature_method=HMAC-SHA1&oauth_timestamp.*oauth_version=1.0&pesapal_merchant_reference=.*&pesapal_transaction_tracking_id=.*/).
- to_return(:status => 200, :body => 'pesapal_response_data=transaction_tracking_id,payment_method,payment_status,merchant_reference')
+ @request.to_return(:status => 200, :body => 'pesapal_response_data=transaction_tracking_id,payment_method,payment_status,merchant_reference')
expect(@pesapal.query_payment_details('merchant_reference', 'transaction_tracking_id')).to eq({ :method => 'payment_method',
:status => 'payment_status',
:merchant_reference => 'merchant_reference',
:transaction_tracking_id => 'transaction_tracking_id'
})
end
end
describe '#ipn_listener' do
+ before :each do
+ @request = stub_request(:get, /https:\/\/www.pesapal.com\/API\/QueryPaymentStatus\?oauth_consumer_key=.*oauth_nonce=.*oauth_signature=.*oauth_signature_method=HMAC-SHA1&oauth_timestamp.*oauth_version=1.0&pesapal_merchant_reference=.*&pesapal_transaction_tracking_id=.*/)
+ end
+
it 'gets ipn response for pending status' do
- stub_request(:get, /https:\/\/www.pesapal.com\/API\/QueryPaymentStatus\?oauth_consumer_key=.*oauth_nonce=.*oauth_signature=.*oauth_signature_method=HMAC-SHA1&oauth_timestamp.*oauth_version=1.0&pesapal_merchant_reference=.*&pesapal_transaction_tracking_id=.*/).
- to_return(:status => 200, :body => 'pesapal_response_data=PENDING')
+ @request.to_return(:status => 200, :body => 'pesapal_response_data=PENDING')
expect(@pesapal.ipn_listener('CHANGE', 'merchant_reference', 'transaction_tracking_id')).to eq({:status => 'PENDING', :response => nil})
end
it 'gets ipn response for completed status' do
- stub_request(:get, /https:\/\/www.pesapal.com\/API\/QueryPaymentStatus\?oauth_consumer_key=.*oauth_nonce=.*oauth_signature=.*oauth_signature_method=HMAC-SHA1&oauth_timestamp.*oauth_version=1.0&pesapal_merchant_reference=.*&pesapal_transaction_tracking_id=.*/).
- to_return(:status => 200, :body => 'pesapal_response_data=COMPLETED')
+ @request.to_return(:status => 200, :body => 'pesapal_response_data=COMPLETED')
expect(@pesapal.ipn_listener('CHANGE', 'merchant_reference', 'transaction_tracking_id')).to eq({:status => 'COMPLETED', :response => 'pesapal_notification_type=CHANGE&pesapal_transaction_tracking_id=transaction_tracking_id&pesapal_merchant_reference=merchant_reference'})
end
it 'gets ipn response for failed status' do
- stub_request(:get, /https:\/\/www.pesapal.com\/API\/QueryPaymentStatus\?oauth_consumer_key=.*oauth_nonce=.*oauth_signature=.*oauth_signature_method=HMAC-SHA1&oauth_timestamp.*oauth_version=1.0&pesapal_merchant_reference=.*&pesapal_transaction_tracking_id=.*/).
- to_return(:status => 200, :body => 'pesapal_response_data=FAILED')
+ @request.to_return(:status => 200, :body => 'pesapal_response_data=FAILED')
expect(@pesapal.ipn_listener('CHANGE', 'merchant_reference', 'transaction_tracking_id')).to eq({:status => 'FAILED', :response => 'pesapal_notification_type=CHANGE&pesapal_transaction_tracking_id=transaction_tracking_id&pesapal_merchant_reference=merchant_reference'})
end
it 'gets ipn response for invalid status' do
- stub_request(:get, /https:\/\/www.pesapal.com\/API\/QueryPaymentStatus\?oauth_consumer_key=.*oauth_nonce=.*oauth_signature=.*oauth_signature_method=HMAC-SHA1&oauth_timestamp.*oauth_version=1.0&pesapal_merchant_reference=.*&pesapal_transaction_tracking_id=.*/).
- to_return(:status => 200, :body => 'pesapal_response_data=INVALID')
+ @request.to_return(:status => 200, :body => 'pesapal_response_data=INVALID')
expect(@pesapal.ipn_listener('CHANGE', 'merchant_reference', 'transaction_tracking_id')).to eq({:status => 'INVALID', :response => nil})
end
end
+ end
+
+ private
+
+ def default_credentials
+ { :callback_url => 'http://0.0.0.0:3000/pesapal/callback',
+ :consumer_key => '<YOUR_CONSUMER_KEY>',
+ :consumer_secret => '<YOUR_CONSUMER_SECRET>'
+ }
+ end
+
+ def demo_endpoints
+ { :postpesapaldirectorderv4 => 'http://demo.pesapal.com/API/PostPesapalDirectOrderV4',
+ :querypaymentstatus=>'http://demo.pesapal.com/API/QueryPaymentStatus',
+ :querypaymentdetails=>'http://demo.pesapal.com/API/QueryPaymentDetails'
+ }
+ end
+
+ def production_endpoints
+ { :postpesapaldirectorderv4 => 'https://www.pesapal.com/API/PostPesapalDirectOrderV4',
+ :querypaymentstatus=>'https://www.pesapal.com/API/QueryPaymentStatus',
+ :querypaymentdetails=>'https://www.pesapal.com/API/QueryPaymentDetails'
+ }
end
end