diff --git a/lib/datatrans/json/transaction/merchant_authorize.rb b/lib/datatrans/json/transaction/merchant_authorize.rb index 8488325..c0fcd45 100644 --- a/lib/datatrans/json/transaction/merchant_authorize.rb +++ b/lib/datatrans/json/transaction/merchant_authorize.rb @@ -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 diff --git a/spec/json/merchant_authorize_spec.rb b/spec/json/merchant_authorize_spec.rb index ad04cc9..fbdc722 100644 --- a/spec/json/merchant_authorize_spec.rb +++ b/spec/json/merchant_authorize_spec.rb @@ -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", @@ -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", @@ -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)