lib/active_merchant/billing/gateways/visanet_peru.rb in activemerchant-1.125.0 vs lib/active_merchant/billing/gateways/visanet_peru.rb in activemerchant-1.126.0

- old
+ new

@@ -88,12 +88,12 @@ CURRENCY_CODES = Hash.new { |_h, k| raise ArgumentError.new("Unsupported currency: #{k}") } CURRENCY_CODES['USD'] = 840 CURRENCY_CODES['PEN'] = 604 def add_invoice(params, money, options) - # Visanet Peru expects a 9-digit numeric purchaseNumber - params[:purchaseNumber] = (SecureRandom.random_number(900_000_000) + 100_000_000).to_s + # Visanet Peru expects a 12-digit alphanumeric purchaseNumber + params[:purchaseNumber] = generate_purchase_number_stamp params[:externalTransactionId] = options[:order_id] params[:amount] = amount(money) params[:currencyId] = CURRENCY_CODES[options[:currency] || currency(money)] end @@ -138,9 +138,13 @@ params[:ruc] = options[:ruc] end def split_authorization(authorization) authorization.split('|') + end + + def generate_purchase_number_stamp + (Time.now.to_f.round(2) * 100).to_i.to_s end def commit(action, params, options = {}) raw_response = ssl_request(method(action), url(action, params, options), params.to_json, headers) response = parse(raw_response)