Skip to content

Commit

Permalink
Merge pull request #68 from visini/add-twint-params-support
Browse files Browse the repository at this point in the history
Add support for TWINT params
  • Loading branch information
andyundso authored Apr 11, 2024
2 parents b9a3506 + 41a2d01 commit b61ead5
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/datatrans/json/transaction/merchant_authorize.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,17 @@ def process
def request_body
auto_settle = params[:auto_settle].nil? ? true : params[:auto_settle]

{
body = {
currency: params[:currency],
refno: params[:refno],
amount: params[:amount],
card: params[:card],
autoSettle: auto_settle
}

body[:card] = params[:card] if params[:card].present?
body[:TWI] = params[:TWI] if params[:TWI].present?

body
end
end

Expand Down
28 changes: 28 additions & 0 deletions spec/json/merchant_authorize_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,16 @@
auto_settle: true
}

@valid_params_twint = {
currency: "CHF",
refno: "B4B4B4B4B",
amount: 1000,
TWI: {
alias: "123456"
},
auto_settle: true
}

@expected_request_body = {
currency: "CHF",
refno: "B4B4B4B4B",
Expand All @@ -41,6 +51,16 @@
autoSettle: true
}

@expected_request_body_twint = {
currency: "CHF",
refno: "B4B4B4B4B",
amount: 1000,
TWI: {
alias: "123456"
},
autoSettle: true
}

@invalid_params = {
currency: "CHF",
refno: "B4B4B4B4B",
Expand Down Expand Up @@ -78,6 +98,14 @@
end
end

context "with TWI specified" do
it "handles TWI correctly in request_body" do
request = Datatrans::JSON::Transaction::MerchantAuthorize.new(@datatrans, @valid_params_twint)

expect(request.request_body).to eq(@expected_request_body_twint)
end
end

context "failed response" do
before do
allow_any_instance_of(Datatrans::JSON::Transaction::MerchantAuthorize).to receive(:process).and_return(@failed_response)
Expand Down

0 comments on commit b61ead5

Please sign in to comment.