diff --git a/lib/cloud_payments/models/transaction.rb b/lib/cloud_payments/models/transaction.rb index 66b4079..20e9a05 100644 --- a/lib/cloud_payments/models/transaction.rb +++ b/lib/cloud_payments/models/transaction.rb @@ -42,6 +42,7 @@ class Transaction < Model property :status_code property :reason property :reason_code + property :refunded property :card_holder_message property :token @@ -80,5 +81,9 @@ def cancelled? def declined? status == DECLINED end + + def refunded? + refunded + end end end diff --git a/spec/cloud_payments/models/transaction_spec.rb b/spec/cloud_payments/models/transaction_spec.rb index b099812..f5dcbf5 100644 --- a/spec/cloud_payments/models/transaction_spec.rb +++ b/spec/cloud_payments/models/transaction_spec.rb @@ -40,6 +40,7 @@ status_code: 3, reason: 'Approved', reason_code: 0, + refunded: false, card_holder_message: 'Payment successful', name: 'CARDHOLDER NAME', token: 'a4e67841-abb0-42de-a364-d1d8f9f4b3c0' @@ -80,6 +81,7 @@ specify{ expect(subject.card_holder_message).to eq('Payment successful') } specify{ expect(subject.name).to eq('CARDHOLDER NAME') } specify{ expect(subject.token).to eq('a4e67841-abb0-42de-a364-d1d8f9f4b3c0') } + specify{ expect(subject.refunded).to eq(false) } context 'without any attributes' do let(:attributes){ {} } @@ -117,6 +119,7 @@ it_behaves_like :not_raise_without_attribute, :issuer_bank_country it_behaves_like :not_raise_without_attribute, :reason it_behaves_like :not_raise_without_attribute, :reason_code + it_behaves_like :not_raise_without_attribute, :refunded it_behaves_like :not_raise_without_attribute, :card_holder_message it_behaves_like :not_raise_without_attribute, :name it_behaves_like :not_raise_without_attribute, :token @@ -254,5 +257,22 @@ specify{ expect(subject.ip_location).to be_nil } end end + + describe '#refunded?' do + context do + let(:attributes) { { refunded: false } } + specify { expect(subject.refunded?).to be_falsey } + end + + context do + let(:attributes) { { refunded: true } } + specify { expect(subject.refunded?).to be_truthy } + end + + context do + let(:attributes) { { refunded: nil } } + specify { expect(subject.refunded?).to be_falsey } + end + end end end diff --git a/spec/cloud_payments/namespaces/payments_spec.rb b/spec/cloud_payments/namespaces/payments_spec.rb index 55264ba..6aba2f1 100644 --- a/spec/cloud_payments/namespaces/payments_spec.rb +++ b/spec/cloud_payments/namespaces/payments_spec.rb @@ -123,6 +123,12 @@ specify{ expect(subject.get(transaction_id).id).to eq(transaction_id) } specify{ expect(subject.get(transaction_id).reason).to eq('Approved') } end + + context 'transaction is refunded' do + before{ stub_api_request('payments/get/refunded').perform } + specify{ expect(subject.get(transaction_id)).to be_completed } + specify{ expect(subject.get(transaction_id)).to be_refunded } + end end context 'config.raise_banking_errors = true' do diff --git a/spec/fixtures/apis/payments/get/failed.yml b/spec/fixtures/apis/payments/get/failed.yml index 771a3db..4688f9b 100644 --- a/spec/fixtures/apis/payments/get/failed.yml +++ b/spec/fixtures/apis/payments/get/failed.yml @@ -37,6 +37,7 @@ "StatusCode": 5, "Reason": "InsufficientFunds", "ReasonCode": 5051, + "Refunded": false, "CardHolderMessage": "Insufficient funds on account", "Name": "CARDHOLDER NAME" }, diff --git a/spec/fixtures/apis/payments/get/refunded.yml b/spec/fixtures/apis/payments/get/refunded.yml new file mode 100644 index 0000000..23bf112 --- /dev/null +++ b/spec/fixtures/apis/payments/get/refunded.yml @@ -0,0 +1,49 @@ +--- +:request: + :url: '/payments/get' + :body: '{"TransactionId":12345}' +:response: + :body: > + { + "Model":{ + "TransactionId":12345, + "Amount":10.0, + "Currency":"RUB", + "CurrencyCode":0, + "InvoiceId":"1234567", + "AccountId":"user_x", + "Email":null, + "Description":"Payment for goods on example.com", + "JsonData":null, + "CreatedDate":"\/Date(1401718880000)\/", + "CreatedDateIso":"2014-08-09T11:49:41", + "AuthDate":"\/Date(1401733880523)\/", + "AuthDateIso":"2014-08-09T11:49:42", + "ConfirmDate":"\/Date(1401733880523)\/", + "ConfirmDateIso":"2014-08-09T11:49:42", + "AuthCode":"123456", + "TestMode":true, + "IpAddress":"195.91.194.13", + "IpCountry":"RU", + "IpCity":"Ufa", + "IpRegion":"Bashkortostan Republic", + "IpDistrict":"Volga Federal District", + "IpLatitude":54.7355, + "IpLongitude":55.991982, + "CardFirstSix":"411111", + "CardLastFour":"1111", + "CardType":"Visa", + "CardTypeCode":0, + "IssuerBankCountry":"RU", + "Status":"Completed", + "StatusCode":3, + "Reason":"Approved", + "ReasonCode":0, + "Refunded": true, + "CardHolderMessage":"Payment successful", + "Name":"CARDHOLDER NAME", + "Token":"a4e67841-abb0-42de-a364-d1d8f9f4b3c0" + }, + "Success":true, + "Message": null + } diff --git a/spec/fixtures/apis/payments/get/successful.yml b/spec/fixtures/apis/payments/get/successful.yml index 7a91df9..b8c6d41 100644 --- a/spec/fixtures/apis/payments/get/successful.yml +++ b/spec/fixtures/apis/payments/get/successful.yml @@ -39,6 +39,7 @@ "StatusCode":3, "Reason":"Approved", "ReasonCode":0, + "Refunded": false, "CardHolderMessage":"Payment successful", "Name":"CARDHOLDER NAME", "Token":"a4e67841-abb0-42de-a364-d1d8f9f4b3c0"