Skip to content

Commit

Permalink
IN-392 Creates returns services
Browse files Browse the repository at this point in the history
  • Loading branch information
reinaldob committed Dec 16, 2014
1 parent 4ac8fbb commit c2cb1ff
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions lib/SF_services/return.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
module SFService
class Return < Base
def initialize(config)
super("Note", config)
end

def is_present?(number)
results = salesforce.query("select Id from Note where Title = 'Return:#{number}'")
results.any? ? results.first.fetch('Id') : nil
end

def find_order(id)
results = salesforce.query("select Id from Opportunity where Name = '#{id}'")
results.any? ? results.first['Id'] : nil
end

def upsert!(payment_attr = {}, order_code, email)
order_id = find_order(order_code)

payment_attr = payment_attr.merge( { 'ParentId' => order_id } ) if order_id.present?

payment_id = is_present?(payment_attr.fetch 'Title')
payment_id.present? ? update!(payment_attr.merge({ Id: payment_id })) : create!(payment_attr)
end
end
end

0 comments on commit c2cb1ff

Please sign in to comment.