spec/veritrans_client_spec.rb in veritrans-2.2.0 vs spec/veritrans_client_spec.rb in veritrans-2.3.0
- old
+ new
@@ -6,19 +6,28 @@
Veritrans.setup do
config.load_config "./spec/configs/real_key.yml"
end
end
+ def test_card_data
+ {
+ card_number: 4811_1111_1111_1114,
+ card_cvv: 123,
+ card_exp_month: 1,
+ card_exp_year: Time.now.year + 1
+ }
+ end
+
it "should use Veritrans.http_options", vcr: false do
Veritrans::Config.stub(:http_options) do
{ omit_default_port: true }
end
api_request = nil
stub_request(:any, /.*/).to_return(lambda { |request|
api_request = request
- {body: request.body}
+ { body: request.body }
})
result = Veritrans.request_with_logging(:get, Veritrans.config.api_host + "/ping", {})
api_request.headers["Host"].should == "api.sandbox.midtrans.com:443"
@@ -30,11 +39,11 @@
end
api_request = nil
stub_request(:any, /.*/).to_return(lambda { |request|
api_request = request
- {body: request.body}
+ { body: request.body }
})
result = Veritrans.request_with_logging(:get, Veritrans.config.api_host + "/ping", {})
api_request.headers["X-Rspec"].should == "ok"
@@ -70,22 +79,23 @@
#p result.request_options
other_result = other_client.status(result.transaction_id)
other_result.status_code.should == 404
- other_result.status_message.should == "The requested resource is not found"
+ other_result.status_message.should == "Transaction doesn't exist."
+
#p other_result.request_options
VCR.configure do |c|
c.allow_http_connections_when_no_cassette = true
end
end
it "should send charge vt-web request" do
VCR.use_cassette('charge_vtweb') do
- result = Veritrans.charge('vtweb', transaction: { order_id: Time.now.to_s, gross_amount: 100_000 } )
+ result = Veritrans.charge('vtweb', transaction: { order_id: Time.now.to_s, gross_amount: 100_000 })
result.status_message.should == "OK, success do VTWeb transaction, please go to redirect_url"
result.success?.should == true
result.redirect_url.should be_present
end
@@ -103,35 +113,35 @@
it "should send status request" do
VCR.use_cassette('status_fail') do
result = Veritrans.status("not-exists")
result.success?.should == false
- result.status_message.should == "The requested resource is not found"
+ result.status_message.should == "Transaction doesn't exist."
end
end
it "should send status request and get response" do
VCR.use_cassette('status_success') do
- result_charge = Veritrans.charge('permata', transaction: { order_id: Time.now.to_i, gross_amount: 100_000 } )
+ result_charge = Veritrans.charge('permata', transaction: { order_id: Time.now.to_i, gross_amount: 100_000 })
result = Veritrans.status(result_charge.order_id)
result.success?.should == true
- result.status_message.should == "Success, transaction found"
+ result.status_message.should == "Success, transaction is found"
result.transaction_status.should == "pending"
end
end
it "should send status request and get response" do
VCR.use_cassette('cancel_failed') do
result = Veritrans.cancel("not-exists")
result.success?.should == false
- result.status_message.should == "The requested resource is not found"
+ result.status_message.should == "Transaction doesn't exist."
end
end
it "should send status request and get response" do
VCR.use_cassette('cancel_success') do
- result_charge = Veritrans.charge('permata', transaction: { order_id: Time.now.to_i, gross_amount: 100_000 } )
+ result_charge = Veritrans.charge('permata', transaction: { order_id: Time.now.to_i, gross_amount: 100_000 })
result = Veritrans.cancel(result_charge.order_id)
result.success?.should == true
result.status_message.should == "Success, transaction is canceled"
result.transaction_status.should == "cancel"
end
@@ -143,14 +153,55 @@
result.success?.should == false
result.status_message.should == "The requested resource is not found"
end
end
+ it 'should get token for testing' do
+ VCR.use_cassette('test_token') do
+ result = Veritrans.test_token(test_card_data)
+ result.should be_a_kind_of(String)
+ end
+ end
+
+ # Can only refund after it has been settled after one day
+ it 'should send refund request' do
+ VCR.use_cassette('refund_failed') do
+ result = Veritrans.refund('1415110696')
+ result.success?.should == false
+ result.status_message.should == 'Merchant cannot modify the status of the transaction'
+ end
+ end
+
it "should send capture request" do
VCR.use_cassette('capture_failed') do
result = Veritrans.capture("not-exists", 1000)
result.success?.should == false
result.status_message.should == "The requested resource is not found"
+ end
+ end
+
+ it 'should send deny request' do
+ VCR.use_cassette('deny_failed') do
+ Timecop.freeze(Time.utc(2019, 4, 1)) do
+ order_id = Time.now.to_i.to_s
+
+ charge_result = Veritrans.charge(
+ payment_type: 'credit_card',
+ credit_card: {
+ token_id: Veritrans.test_token(test_card_data)
+ },
+ transaction_details: {
+ order_id: order_id,
+ gross_amount: 3000
+ }
+ )
+
+ charge_result.status_message.should == "Success, Credit Card transaction is successful"
+
+ result = Veritrans.deny(order_id)
+ result.success?.should == false
+ result.status_message.should == 'Transaction status cannot be updated.'
+ end
end
end
it "should send expire request" do
VCR.use_cassette('expire_success', record: :once) do
\ No newline at end of file