diff --git a/lib/mangopay/pay_in.rb b/lib/mangopay/pay_in.rb index 55fe28d..38a7ab6 100644 --- a/lib/mangopay/pay_in.rb +++ b/lib/mangopay/pay_in.rb @@ -187,6 +187,16 @@ def self.url(*) end end + module Klarna + class Web < Resource + include HTTPCalls::Create + + def self.url(*) + "#{MangoPay.api_path}/payins/payment-methods/klarna" + end + end + end + module RecurringPayments class Recurring < Resource include HTTPCalls::Create diff --git a/spec/mangopay/payin_klarna_web_spec.rb b/spec/mangopay/payin_klarna_web_spec.rb new file mode 100644 index 0000000..e9989b3 --- /dev/null +++ b/spec/mangopay/payin_klarna_web_spec.rb @@ -0,0 +1,32 @@ +describe MangoPay::PayIn::Klarna::Web, type: :feature do + include_context 'wallets' + include_context 'payins' + + def check_type_and_status(payin) + expect(payin['Type']).to eq('PAYIN') + expect(payin['Nature']).to eq('REGULAR') + expect(payin['PaymentType']).to eq('KLARNA') + expect(payin['ExecutionType']).to eq('WEB') + expect(payin['Status']).to eq('CREATED') + end + + describe 'CREATE' do + it 'creates a klarna web payin' do + created = new_payin_klarna_web + expect(created['Id']).not_to be_nil + expect(created['ReturnURL']).not_to be_nil + check_type_and_status(created) + end + end + + describe 'FETCH' do + it 'fetches a payin' do + created = new_payin_klarna_web + fetched = MangoPay::PayIn.fetch(created['Id']) + expect(fetched['Id']).to eq(created['Id']) + check_type_and_status(created) + check_type_and_status(fetched) + end + end +end + diff --git a/spec/mangopay/shared_resources.rb b/spec/mangopay/shared_resources.rb index a869cf1..0f66adc 100644 --- a/spec/mangopay/shared_resources.rb +++ b/spec/mangopay/shared_resources.rb @@ -508,6 +508,66 @@ def create_new_document(user) ) end + ############################################### + # KLARNA/web + ############################################### + let(:new_payin_klarna_web) do + MangoPay::PayIn::Klarna::Web.create( + AuthorId: new_natural_user['Id'], + CreditedWalletId: new_wallet['Id'], + DebitedFunds: {Currency: 'EUR', Amount: 400}, + Fees: {Currency: 'EUR', Amount: 10}, + ReturnURL: 'http://www.my-site.com/returnURL', + LineItems: [ + { + Name: "running shoes", + Quantity: 1, + UnitAmount: 200, + TaxAmount: 0, + Description: "seller1 ID" + }, + { + Name: "running shoes", + Quantity: 1, + UnitAmount: 200, + TaxAmount: 0, + Description: "seller2 ID" + } + ], + Country: 'FR', + Culture: 'FR', + Phone: '33#607080900', + Email: 'mango@mangopay.com', + AdditionalData: '{}', + Billing: { + Address: { + AddressLine1: 'AddressLine1', + AddressLine2: 'AddressLine2', + City: 'City', + Region: 'Region', + PostalCode: 'PostalCode', + Country: 'FR' + }, + FirstName: 'Joe', + LastName: 'Blogs' + }, + Shipping: { + Address: { + AddressLine1: 'AddressLine1', + AddressLine2: 'AddressLine2', + City: 'City', + Region: 'Region', + PostalCode: 'PostalCode', + Country: 'FR' + }, + FirstName: 'Joe', + LastName: 'Blogs' + }, + MerchantOrderId: 'afd48-879d-48fg', + Tag: 'Test PayIn/Klarna/Web' + ) + end + ############################################### # PAYPAL/direct ###############################################