Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # TODO JB : should be restful and renamed !
- class Api::CommerceController < ApplicationController
- before_filter :authenticate_user!
- # Payin to MangoPay wallet
- def deposit
- # /card/:mango_pay_card_id/wallet/:mango_pay_wallet_id/amount/:amount'
- if current_user.mango_pay_id.nil?
- render :json => {status: 422, :error => "Missing MangoPay ID"}, :status => 422
- end
- payin = MangoPay::PayIn::Card::Direct.create({
- AuthorId: current_user.mango_pay_id,
- CardId: params[:mango_pay_card_id],
- CardType: 'CB_VISA_MASTERCARD',
- CreditedUserId: current_user.mango_pay_id,
- CreditedWalletId: params[:mango_pay_wallet_id],
- DebitedFunds: {Currency: 'EUR', Amount: params[:amount]},
- Fees: {Currency: 'EUR', Amount: 0},
- SecureModeReturnURL: 'http://test.com',
- Tag: params["Test"]
- })
- render json: payin
- end
- def wire_in
- organisation_id = params[:organisation_id]
- org = Organisation.find(organisation_id)
- fund_raiser_id = params[:fund_raiser_id]
- mango_pay_wallet_id = params[:mango_pay_wallet_id]
- iban = params[:iban]
- bic = params[:bic]
- amount = params[:amount]
- tip = 0
- if params[:tip]
- tip = params[:tip].to_f
- end
- ldl_rate = 0
- if org.tarif
- ldl_rate = org.tarif.rate
- end
- ldl_fee = 0
- mango_fee = 0
- fees = 0
- tag = params[:tag] or "Test Donation"
- anonymous = params[:anonymous]
- ##
- # Validations
- ##
- # Check that active user has MangoPay ID
- @user = UserDecorator.decorate(current_user)
- if @user.mango_pay_id.nil?
- render :json => {status: 422, :error => "Donating user missing MangoPay ID"}, :status => 422
- end
- # Validate organisation
- if not organisation_id.nil?
- organisation = OrganisationDecorator.decorate(Organisation.find(organisation_id))
- donatee = organisation
- if donatee.nil?
- render :json => {status: 422, :error => "Donation target organisation does not exist"}, :status => 422
- end
- else
- render :json => {status: 422, :error => "Organisation parameter missing"}, :status => 422
- end
- # Validate fund raiser
- if not fund_raiser_id.nil?
- fund_raiser = FundRaiserDecorator.decorate(FundRaiser.find(fund_raiser_id))
- donatee = fund_raiser
- if donatee.nil?
- render :json => {status: 422, :error => "Donation target fund raiser does not exist"}, :status => 422
- end
- end
- # Validate donatee's MangoPay integration
- begin
- if donatee.mango_pay_id.nil? or donatee.wallet.nil?
- render :json => {status: 422, :error => "Donation target missing MangoPay ID and/or wallet"}, :status => 422
- end
- rescue
- logger.warn($!)
- # render :json => {status: 422, :error => $!}, :status => 422
- end
- # Check for missing donation target
- if organisation.nil?
- elsif not fund_raiser.nil?
- else
- if organisation.mango_pay_id.nil?
- render :json => {status: 422, :error => "Donation target missing MangoPay ID"}, :status => 422
- end
- end
- # register bank acct and donate
- if iban
- begin
- self.register_bank iban, bic, tag
- if amount.to_f * 0.019 < 0.55
- if ldl_rate > 0
- ldl_fee = amount.to_f * ldl_rate
- else
- ldl_fee = amount.to_f * 0.05
- end
- mango_fee = 0.55
- fees = ldl_fee + mango_fee
- else
- if ldl_rate > 0
- ldl_fee = amount.to_f * ldl_rate
- else
- ldl_fee = amount.to_f * 0.05
- end
- mango_fee = amount.to_f * 0.019
- fees = ldl_fee + mango_fee
- end
- # Add TVA
- tva = ldl_fee * 0.2
- fees += tva
- debit_funds = ((amount.to_f + tip.to_f) * 100)
- debit_fees = ((fees.to_f + tip.to_f) * 100)
- payin = MangoPay::PayIn::BankWire::Direct.create({
- AuthorId: @user.mango_pay_id.to_s,
- Tag: tag,
- CreditedUserId: donatee.mango_pay_id.to_s,
- CreditedWalletId: donatee.wallet[:id].to_s,
- DeclaredDebitedFunds: {Currency: 'EUR', Amount: debit_funds},
- DeclaredFees: {Currency: 'EUR', Amount: debit_fees}
- })
- if payin['Status'] == 'CREATED'
- # Create donation from transaction
- @donation = Donation.new
- @donation.user = @user
- @donation.organisation = organisation
- @donation.fund_raiser = fund_raiser unless fund_raiser.nil?
- @donation.mango_pay_id = payin['Id']
- @donation.name = "Test Donation"
- @donation.amount = amount
- @donation.tip = tip
- @donation.mango_fee = mango_fee
- @donation.ldl_fee = ldl_fee
- @donation.fee = fees
- @donation.tva = tva
- @donation.total = amount.to_f - fees
- @donation.anonymous = anonymous
- @donation.save
- #Now give them the money!
- performPayout donatee, amount.to_f, fees.to_f, @donation, fund_raiser
- else
- # Error
- render :json => {status: payin['Status'], :error => payin}, :status => 422
- end
- end
- end
- end
- def pay_saved_card
- ##
- # Parameters
- ##
- organisation_id = params[:organisation_id]
- org = Organisation.find(organisation_id)
- fund_raiser_id = params[:fund_raiser_id]
- mango_pay_wallet_id = params[:mango_pay_wallet_id]
- amount = params[:amount]
- tip = 0
- if params[:tip]
- tip = params[:tip].to_f
- end
- ldl_rate = 0
- if org.tarif
- ldl_rate = org.tarif.rate
- end
- ldl_fee = 0
- mango_fee = 0
- fees = 0
- tag = params[:tag] or "Test Donation"
- anonymous = params[:anonymous]
- ##
- # Validations
- ##
- # Check that active user has MangoPay ID
- @user = UserDecorator.decorate(current_user)
- if @user.mango_pay_id.nil?
- render :json => {status: 422, :error => "Donating user missing MangoPay ID"}, :status => 422
- end
- # Validate organisation
- if not organisation_id.nil?
- organisation = OrganisationDecorator.decorate(Organisation.find(organisation_id))
- donatee = organisation
- if donatee.nil?
- render :json => {status: 422, :error => "Donation target organisation does not exist"}, :status => 422
- end
- else
- render :json => {status: 422, :error => "Organisation parameter missing"}, :status => 422
- end
- # Validate fund raiser
- if not fund_raiser_id.nil?
- fund_raiser = FundRaiserDecorator.decorate(FundRaiser.find(fund_raiser_id))
- if donatee.nil?
- render :json => {status: 422, :error => "Donation target fund raiser does not exist"}, :status => 422
- end
- end
- # Validate donatee's MangoPay integration
- begin
- if donatee.mango_pay_id.nil? or donatee.wallet.nil?
- render :json => {status: 422, :error => "Donation target missing MangoPay ID and/or wallet"}, :status => 422
- end
- rescue
- logger.warn($!)
- # render :json => {status: 422, :error => $!}, :status => 422
- end
- # Check for missing donation target
- if organisation.nil?
- else
- if organisation.mango_pay_id.nil?
- render :json => {status: 422, :error => "Donation target missing MangoPay ID"}, :status => 422
- end
- end
- # Validate that card/wallet is actually active user's card/wallet
- # if not mango_pay_card_id.nil? and not @user.cards.any? { |card| card[:id].to_s == mango_pay_card_id }
- # raise Exception, "Donation card does not belong to active user"
- # elsif not mango_pay_wallet_id.nil? and not @user.wallets.any? { |wallet| wallet[:id].to_s == mango_pay_wallet_id }
- # raise Exception, "Donation wallet does not belong to active user"
- # end
- # Check for card payment
- begin
- amount = amount.to_f
- if amount.to_f * 0.019 < 0.55
- if ldl_rate > 0
- ldl_fee = amount.to_f * ldl_rate
- else
- ldl_fee = amount.to_f * 0.05
- end
- mango_fee = 0.55
- fees = ldl_fee + mango_fee
- else
- if ldl_rate > 0
- ldl_fee = amount.to_f * ldl_rate
- else
- ldl_fee = amount.to_f * 0.05
- end
- mango_fee = amount.to_f * 0.019
- fees = ldl_fee + mango_fee
- end
- # Add TVA
- tva = ldl_fee * 0.2
- fees += tva
- # Create donation from transaction
- @donation = Donation.new
- @donation.user = @user
- @donation.organisation = organisation
- @donation.fund_raiser = fund_raiser unless fund_raiser.nil?
- # @donation.mango_pay_id = payin['Id']
- @donation.name = 'Test Donation'
- @donation.amount = amount
- @donation.tip = tip
- @donation.mango_fee = mango_fee
- @donation.ldl_fee = ldl_fee
- @donation.fee = fees
- @donation.tva = tva
- @donation.total = amount.to_f - fees
- @donation.anonymous = anonymous
- @donation.save
- payin_payload = {
- AuthorId: @user.mango_pay_id.to_s,
- CreditedUserId: donatee.mango_pay_id.to_s,
- CreditedWalletId: donatee.wallet[:id].to_s,
- DebitedFunds: {Currency: 'EUR', Amount: ((amount + tip) * 100)},
- Fees: {Currency: 'EUR', Amount: ((fees + tip) * 100)},
- CardId: @user.mango_pay_card.to_s,
- CardType: 'CB_VISA_MASTERCARD',
- SecureMode: "DEFAULT",
- }
- if !fund_raiser.nil?
- payin_payload['SecureModeReturnURL'] = Rails.application.config.FRONTEND + '/merci/collectes/' + @donation.order
- else
- payin_payload['SecureModeReturnURL'] = Rails.application.config.FRONTEND + '/merci/' + @donation.order
- end
- payin = MangoPay::PayIn::Card::Direct.create(payin_payload)
- if payin['Status'] == 'SUCCEEDED' || payin['Status'] == 'CREATED'
- @donation.mango_pay_id = payin['Id']
- @donation.save
- #Now give them the money!
- if payin['Status'] == 'SUCCEEDED'
- performPayout donatee, amount, fees, @donation, fund_raiser
- else
- @donation.awaiting_confirmation = true
- @donation.save
- render :json => {callback: payin['SecureModeRedirectURL']}
- end
- else
- if payin['ResultCode'] == '002999'
- #KYC error
- if !@donation.user.enterprise
- render :json => {needs_kyc: '/kyc/user/' + @donation.order}
- else
- render :json => {needs_kyc: '/kyc/entreprise/' + @donation.order}
- end
- else
- # Error
- @donation.destroy
- render :json => {status: payin['Status'], :error => payin}, :status => 422
- end
- end
- end
- end
- # Payin to MangoPay wallet
- def donate
- ##
- # Parameters
- ##
- if not params[:iban].nil?
- wire_in
- return
- end
- organisation_id = params[:organisation_id]
- org = Organisation.find(organisation_id)
- fund_raiser_id = params[:fund_raiser_id]
- mango_pay_wallet_id = params[:mango_pay_wallet_id]
- card_number = params[:card_number]
- card_expiry = params[:card_expiry]
- card_code = params[:card_code]
- amount = params[:amount]
- tip = 0
- if params[:tip]
- tip = params[:tip].to_f
- end
- ldl_rate = 0
- if org.tarif
- ldl_rate = org.tarif.rate
- end
- ldl_fee = 0
- mango_fee = 0
- fees = 0
- tag = params[:tag] or "Test Donation"
- anonymous = params[:anonymous]
- ##
- # Validations
- ##
- # Check that active user has MangoPay ID
- @user = UserDecorator.decorate(current_user)
- if @user.mango_pay_id.nil?
- render :json => {status: 422, :error => "Donating user missing MangoPay ID"}, :status => 422
- end
- ##
- # Limit test
- ##
- @last_changed = nil
- donation_total = 0
- if @user.mango_pay_date != nil
- @last_changed = @user.mango_pay_date
- else
- @last_changed = Date.new(Time.now.year, 1, 1)
- end
- @user.donations.each do |donation|
- if Date.parse(donation.created_at.to_s) > @last_changed
- donation_total += (donation.amount + donation.tip)
- end
- end
- if donation_total.to_f + amount.to_f + tip.to_f > 2500
- if !@user.enterprise
- # Create MangoPay Natural User
- nattyPayload = {
- Tag: 'LDL_ID_USER_' + @user.id.to_s,
- Email: @user.email,
- FirstName: @user.first_name,
- LastName: @user.last_name,
- Nationality: CountryHelper.nationalityToIso(@user.nationality),
- CountryOfResidence: CountryHelper.countryToIso(@user.country)
- }
- # address
- if !@user.address || !@user.postcode || !@user.city || !@user.country
- nattyPayload['Address'] = "Temp Address"
- else
- if !@user.address2.nil?
- nattyPayload['Address'] = @user.address + ', ' + @user.address2 + ', ' + @user.postcode +
- ', ' + @user.city + ', ' + @user.country
- else
- nattyPayload['Address'] = @user.address + ', ' + @user.postcode + ', ' +
- @user.city + ', ' + @user.country
- end
- end
- # birthday
- if !@user.dob
- nattyPayload['Birthday'] = 489193200
- else
- nattyPayload['Birthday'] = @user.dob.utc.to_time.to_i + 3600
- end
- user = MangoPay::NaturalUser.create(nattyPayload)
- @user.mango_pay_id = user['Id']
- @user.mango_pay_date = DateTime.now
- @user.save
- else
- # Create MangoPay Legal User
- legalPayload = {
- Tag: 'LDL_ID_USER_' + @user.id.to_s,
- Email: @user.email,
- Name: @user.username,
- LegalPersonType: 'BUSINESS',
- LegalRepresentativeFirstName: @user.first_name,
- LegalRepresentativeLastName: @user.last_name,
- LegalRepresentativeNationality: CountryHelper.nationalityToIso(@user.nationality),
- LegalRepresentativeCountryOfResidence: CountryHelper.countryToIso(@user.country_residence)
- }
- if @user.email_representative
- legalPayload['LegalRepresentativeEmail'] = @user.email_representative
- end
- # address
- if !@user.address || !@user.postcode || !@user.city || !@user.country
- legalPayload['HeadquartersAddress'] = "Temp Headquarters Address"
- else
- if !@user.address2.nil?
- legalPayload['HeadquartersAddress'] = @user.address + ', ' + @user.address2 + ', ' + @user.postcode + ', ' + @user.city + ', ' + @user.country
- else
- legalPayload['HeadquartersAddress'] = @user.address + ', ' + @user.postcode + ', ' + @user.city + ', ' + @user.country
- end
- end
- # birthday
- if !@user.dob
- legalPayload['LegalRepresentativeBirthday'] = 489193200
- else
- legalPayload['LegalRepresentativeBirthday'] = @user.dob.utc.to_time.to_i + 3600
- end
- user = MangoPay::LegalUser.create(legalPayload)
- @user.mango_pay_id = user['Id']
- @user.mango_pay_date = Date.new
- @user.save
- end
- end
- # Validate organisation
- if not organisation_id.nil?
- organisation = OrganisationDecorator.decorate(Organisation.find(organisation_id))
- donatee = organisation
- if donatee.nil?
- render :json => {status: 422, :error => "Donation target organisation does not exist"}, :status => 422
- end
- else
- render :json => {status: 422, :error => "Organisation parameter missing"}, :status => 422
- end
- # Validate fund raiser
- if not fund_raiser_id.nil?
- fund_raiser = FundRaiserDecorator.decorate(FundRaiser.find(fund_raiser_id))
- if donatee.nil?
- render :json => {status: 422, :error => "Donation target fund raiser does not exist"}, :status => 422
- end
- end
- # Validate donatee's MangoPay integration
- begin
- if donatee.mango_pay_id.nil? or donatee.wallet.nil?
- render :json => {status: 422, :error => "Donation target missing MangoPay ID and/or wallet"}, :status => 422
- end
- rescue
- logger.warn($!)
- # render :json => {status: 422, :error => $!}, :status => 422
- end
- # Check for missing donation target
- if organisation.nil?
- else
- if organisation.mango_pay_id.nil?
- render :json => {status: 422, :error => "Donation target missing MangoPay ID"}, :status => 422
- end
- end
- # Validate that card/wallet is actually active user's card/wallet
- # if not mango_pay_card_id.nil? and not @user.cards.any? { |card| card[:id].to_s == mango_pay_card_id }
- # raise Exception, "Donation card does not belong to active user"
- # elsif not mango_pay_wallet_id.nil? and not @user.wallets.any? { |wallet| wallet[:id].to_s == mango_pay_wallet_id }
- # raise Exception, "Donation wallet does not belong to active user"
- # end
- # Check for card payment
- if card_number
- begin
- card = self.register(card_number, card_expiry, card_code)
- if card['ResultMessage'] == 'Success'
- #save card if applicable
- if params[:save] == true
- if @user.mango_pay_card
- MangoPay::Card.update(@user.mango_pay_card, {
- Active: 'false'
- })
- end
- cc = params[:card_number].split('')
- cc[4..11] = %w(X X X X X X X X)
- @user.active_card_number = cc.join('')
- @user.mango_pay_card = card['CardId']
- # @user.active_card_month = params[:card_expiry].to_s[0,2]
- # @user.active_card_year = params[:card_expiry].to_s[2,3]
- # @user.active_card_code = params[:card_code]
- @user.save
- end
- else
- logger.warn(card['ResultMessage'])
- end
- amount = amount.to_f
- if amount.to_f * 0.019 < 0.55
- if ldl_rate > 0
- ldl_fee = amount.to_f * ldl_rate
- else
- ldl_fee = amount.to_f * 0.05
- end
- mango_fee = 0.55
- fees = ldl_fee + mango_fee
- else
- if ldl_rate > 0
- ldl_fee = amount.to_f * ldl_rate
- else
- ldl_fee = amount.to_f * 0.05
- end
- mango_fee = amount.to_f * 0.019
- fees = ldl_fee + mango_fee
- end
- # Add TVA
- tva = ldl_fee * 0.2
- fees += tva
- # Create donation from transaction
- @donation = Donation.new
- @donation.user = @user
- @donation.organisation = organisation
- @donation.fund_raiser = fund_raiser unless fund_raiser.nil?
- # @donation.mango_pay_id = payin['Id']
- @donation.name = 'Test Donation'
- @donation.amount = amount
- @donation.tip = tip
- @donation.mango_fee = mango_fee
- @donation.ldl_fee = ldl_fee
- @donation.fee = fees
- @donation.tva = tva
- @donation.total = amount.to_f - fees
- @donation.anonymous = anonymous
- @donation.save
- payin_payload = {
- AuthorId: @user.mango_pay_id.to_s,
- CreditedUserId: donatee.mango_pay_id.to_s,
- CreditedWalletId: donatee.wallet[:id].to_s,
- DebitedFunds: {Currency: 'EUR', Amount: ((amount + tip) * 100)},
- Fees: {Currency: 'EUR', Amount: ((fees + tip) * 100)},
- CardId: card['CardId'].to_s,
- CardType: 'CB_VISA_MASTERCARD',
- SecureMode: "DEFAULT",
- }
- # Forcing update
- if !fund_raiser.nil?
- payin_payload['SecureModeReturnURL'] = Rails.application.config.FRONTEND + '/merci/collectes/' + @donation.order
- else
- payin_payload['SecureModeReturnURL'] = Rails.application.config.FRONTEND + '/merci/' + @donation.order
- end
- payin = MangoPay::PayIn::Card::Direct.create(payin_payload)
- if payin['Status'] == 'SUCCEEDED' || payin['Status'] == 'CREATED'
- @donation.mango_pay_id = payin['Id']
- @donation.save
- if params[:save] != true
- MangoPay::Card.update(card['CardId'], {
- Active: 'false'
- })
- end
- #Now give them the money!
- if payin['Status'] == 'SUCCEEDED'
- performPayout donatee, amount, fees, @donation, fund_raiser
- else
- @donation.awaiting_confirmation = true
- @donation.save
- render :json => {callback: payin['SecureModeRedirectURL']}
- end
- else
- if payin['ResultCode'] == '002999'
- #KYC error
- if !@donation.user.enterprise
- render :json => {callback: '/kyc/user/' + @donation.order}
- else
- render :json => {callback: '/kyc/entreprise/' + @donation.order}
- end
- else
- # Error
- @donation.destroy
- render :json => {status: payin['Status'], :error => payin}, :status => 422
- end
- end
- end
- end
- end
- def profile
- unless current_user.nil?
- @user = UserDecorator.decorate(current_user)
- end
- end
- # Refund payin or transfer from a MangoPay wallet
- def refund
- # Hmm
- end
- # Unregister MangoPay card
- def unregister
- # /card/:mango_pay_card_id
- end
- def withdraw
- # /wallet/:mango_pay_wallet_id/amount/:amount
- end
- # Register MangoPay card
- def register(card_number, card_expiry, card_code)
- ##
- # Parameters
- ##
- @user = UserDecorator.decorate(current_user)
- tag = "Card_LDL_ID_USER_" + @user.id.to_s
- card_registration = MangoPay::CardRegistration.create({
- UserId: @user.mango_pay_id,
- Currency: 'EUR',
- Tag: tag
- })
- # 2nd step: tokenize by payline (fills-in RegistrationData)
- card_injection = {
- data: card_registration['PreregistrationData'],
- accessKeyRef: card_registration['AccessKey'],
- cardNumber: card_number,
- cardExpirationDate: card_expiry,
- cardCvx: card_code
- }
- card_tokenisation = Net::HTTP.post_form(URI(card_registration['CardRegistrationURL']), card_injection)
- # TODO Better way to do this?
- render :json => {status: 422, errors: [card_tokenisation.body]}, :status => 422 unless (card_tokenisation.is_a?(Net::HTTPOK) && card_tokenisation.body.start_with?('data='))
- card_registration['RegistrationData'] = card_tokenisation.body
- # 3rd step: update (fills-in CardId) and return it
- card_confirmation = MangoPay::CardRegistration.update(card_registration['Id'], {
- RegistrationData: card_registration['RegistrationData']
- })
- return card_confirmation
- end
- # Automatic Payout via Bank Wire
- def performPayout(donatee, amount, fees, donation, fund_raiser)
- unless donatee.mango_pay_bank_id.nil?
- payout = MangoPay::PayOut::BankWire.create({
- AuthorId: donatee.mango_pay_id,
- DebitedFunds: { Currency: 'EUR', Amount: (amount - fees) * 100 },
- Fees: { Currency: 'EUR', Amount: 0 },
- DebitedWalletId: donatee.wallet[:id],
- BankAccountId: donatee.mango_pay_bank_id,
- Communication: 'This is a test',
- Tag: 'Test Bank Wire'
- })
- logger.warn(payout)
- # Send Confirmation Emails
- if !fund_raiser.nil?
- if fund_raiser.alert_creator
- PlatformMailer.donation_notification(fund_raiser, donation).deliver
- end
- end
- json = @donation.to_json(:except => [:receipt_file_name, :receipt_content_type], :methods => [:receipt], :include => [{:fund_raiser => {:include => [{:user => {:include => [:organisation => {:only => [:id, :name]}], :only => [:id, :first_name, :last_name, :enterprise, :username]}}, {:organisation => {:only =>[:id, :name]}}], :methods => [:img_fb]}}, {:organisation => {:only => [:id, :name, :abbrev, :address, :address2, :postcode, :city, :country, :statute, :org_object, :article_200, :article_238_bis, :article_885_0, :president_name], :methods => [:logo_thumb, :logo_original, :signature_thumb, :signature_original], :except => [:organisation_id, :mango_pay_id, :receipt_file_name, :receipt_content_type, :created_at, :updated_at]}}])
- Rails.logger.debug "================= JSON: #{json}"
- render :json => json
- end
- end
- def register_bank(iban, bic, tag)
- # Determine and set address
- @baddress = ''
- if !@user.address2.nil?
- @baddress = @user.address + ', ' + @user.address2 + ', ' + @user.postcode + ', ' + @user.city + ', ' + @user.country
- else
- @baddress = @user.address + ', ' + @user.postcode + ', ' + @user.city + ', ' + @user.country
- end
- # First get bank account if present
- if @user.mango_pay_bank_id
- acct = MangoPay::BankAccount.fetch(@user.mango_pay_id, @user.mango_pay_bank_id)
- # compare and reg if no longer valid
- if @baddress != acct['OwnerAddress'] || iban != acct['IBAN'] || bic != acct['BIC']
- #update
- perform_bank_registration(iban, bic, tag, @baddress)
- end
- else
- # No saved account
- perform_bank_registration(iban, bic, tag, @baddress)
- end
- end
- def perform_bank_registration(iban, bic, tag, address)
- if !@user.enterprise
- reg = MangoPay::BankAccount.create(@user.mango_pay_id, {
- Type: 'IBAN',
- OwnerName: @user.first_name + ' ' + @user.last_name,
- OwnerAddress: address,
- IBAN: iban,
- BIC: bic,
- Tag: tag
- })
- else
- reg = MangoPay::BankAccount.create(@user.mango_pay_id, {
- Type: 'IBAN',
- OwnerName: @user.username,
- OwnerAddress: address,
- IBAN: iban,
- BIC: bic,
- Tag: tag
- })
- end
- @user.mango_pay_bank_id = reg['Id']
- @user.save
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement