Browse Source

Add Sisow Creditcard support

tags/v0.9.0
Bèr Kessels 2 years ago
parent
commit
9a706587e4

+ 13
- 4
app/models/spree/billing_integration.rb View File

@@ -7,18 +7,27 @@ class Spree::BillingIntegration
end
end

class Ideal < Method
class Bancontact < Method
def self.new(*attrs)
super
::Spree::PaymentMethod::SisowBilling::Ideal.new(*attrs)
::Spree::PaymentMethod::SisowBilling::Bancontact.new(*attrs)
end
end
class Bancontact < Method

class Creditcard < Method
def self.new(*attrs)
super
::Spree::PaymentMethod::SisowBilling::Bancontact.new(*attrs)
::Spree::PaymentMethod::SisowBilling::Creditcard.new(*attrs)
end
end

class Ideal < Method
def self.new(*attrs)
super
::Spree::PaymentMethod::SisowBilling::Ideal.new(*attrs)
end
end

class Sofort < Method
def self.new(*attrs)
super

+ 1
- 0
app/models/spree/payment_method/sisow_billing.rb View File

@@ -88,6 +88,7 @@ module Spree
case transaction_type
when "ideal" then Sisow::IdealPayment.new(options)
when "bancontact" then Sisow::BancontactPayment.new(options)
when "creditcard" then Sisow::CreditCardPayment.new(options)
when "sofort" then Sisow::SofortPayment.new(options)
when "paypalec" then Sisow::PaypalPayment.new(options)
else

+ 9
- 0
app/models/spree/payment_method/sisow_billing/creditcard.rb View File

@@ -0,0 +1,9 @@
module Spree
class PaymentMethod::SisowBilling
class Creditcard < SisowPaymentMethod
def payment_type
"creditcard"
end
end
end
end

+ 1
- 0
app/views/spree/checkout/payment/_creditcard.html.erb View File

@@ -0,0 +1 @@
<p data-hook="sisow_creditcard"></p>

+ 1
- 0
lib/spree_billing_sisow/engine.rb View File

@@ -23,6 +23,7 @@ module SpreeBillingSisow
initializer "spree_billing_sisow.register.payment_methods", :after => 'spree.register.payment_methods' do |app|
app.config.spree.payment_methods += [
Spree::PaymentMethod::SisowBilling::Ideal,
Spree::PaymentMethod::SisowBilling::Creditcard,
Spree::PaymentMethod::SisowBilling::Bancontact,
Spree::PaymentMethod::SisowBilling::Sofort,
Spree::PaymentMethod::SisowBilling::Paypalec

+ 63
- 0
spec/features/creditcard_spec.rb View File

@@ -0,0 +1,63 @@
# frozen_string_literal: true

require "spec_helper"

feature "creditcard checkout" do
let(:user) { create(:user) }
let(:order) { OrderWalkthrough.up_to(:payment) }
let(:sisow_request_url) do
"http://www.sisow.nl/Sisow/iDeal/RestHandler.ashx/TransactionRequest"
end

before do
stub_user_with_order(user, order)

stub_request(:get, sisow_request_url).
with(query: hash_including(sisow_request_params)).
to_return(redirect_url_response)
end

context "site has has paymentmethod Creditcard" do
let(:paypal) do
Spree::PaymentMethod::SisowBilling::Creditcard.create!(name: "CreditCard")
end
let(:redirect_url_response) do
stored_response("creditcard_redirect_url_output")
end
let(:sisow_request_params) do
{ amount: "2999",
callbackurl: "http://www.example.com/sisow/#{order.number}",
cancelurl: "http://www.example.com/orders/#{order.number}/checkout/sisow_cancel",
description: "Spree Test Store - Order: #{order.number}",
merchantid: "2537407799",
notifyurl: "http://www.example.com/sisow/#{order.number}",
payment: "creditcard",
purchaseid: order.number,
returnurl: "http://www.example.com/orders/#{order.number}/checkout/sisow_return",
shop_id: '' }
end

before do
allow(order).to receive_messages(available_payment_methods: [paypal])

visit spree.checkout_state_path(:payment)

# Disable redirects, or else we'll be redirected to the actual sisow page
# which cannot be handled by RackTest but is not a good idea either.
# We just want to know that we got the right response.
Capybara.page.driver.options[:follow_redirects] = false
end

scenario "I choose the only payment option Creditcard, and Sisow and redirects me there" do
click_button "Save and Continue"
expect(WebMock).to have_requested(:get, sisow_request_url).with(query: hash_including(sisow_request_params))
response = page.driver.response
expect(response.status).to be 302
expect(response.headers["Location"]).to match(%r(https://www\.sisow\.nl/Sisow/iDeal/Simulator\.aspx\?merchantid=2537407799&txid=\w*&sha1=\w*))
end
end

after do
Capybara.page.driver.options[:follow_redirects] = true
end
end

+ 10
- 0
spec/webmock_files/creditcard_redirect_url_output View File

@@ -0,0 +1,10 @@
HTTP/1.1 200 OK
Cache-Control: private
Content-Type: text/xml; charset=utf-8
Server: Microsoft-IIS/7.0
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Date: Fri, 01 May 2015 08:27:14 GMT
Content-Length: 451
<?xml version="1.0" encoding="UTF-8"?><transactionrequest xmlns="https://www.sisow.nl/Sisow/REST" version="1.0.0"><transaction><issuerurl>https%3a%2f%2fwww.sisow.nl%2fSisow%2fiDeal%2fSimulator.aspx%3fmerchantid%3d2537407799%26txid%3dTEST90488925266%26sha1%3d1eb7cba3b911839f7431ec39103f2c2967399580</issuerurl><trxid>TEST90488925266</trxid></transaction><signature><sha1>0f3236350878aa51d9ec09973ee50175cd99076a</sha1></signature></transactionrequest>

Loading…
Cancel
Save