Guest User

Untitled

a guest
Jun 24th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1. def cim_charge(amount, payment_detail, options = {})
  2. process('charge_cim', amount) do |gw|
  3. gw.create_customer_profile_transaction(
  4. :transaction => {
  5. :customer_profile_id => payment_detail.profile_id,
  6. :customer_payment_profile_id => payment_detail.payment_profile_id,
  7. :type => :auth_capture,
  8. :amount => amount
  9. }
  10. )
  11. end
  12. end
  13.  
  14. private
  15. def process(action, amount = nil)
  16. self.amount = amount
  17. self.action = action
  18.  
  19. gateway = Gateway.get vendor_id
  20. begin
  21. response = yield gateway
  22.  
  23. self.success = response.success?
  24. self.reference = response.authorization
  25. self.message = response.message
  26. self.params = response.params
  27. self.test = response.test?
  28. rescue ActiveMerchant::ActiveMerchantError => e
  29. self.success = false
  30. self.reference = nil
  31. self.message = e.message
  32. self.params = {}
  33. self.test = gateway.test?
  34. end
  35.  
  36. if not self.save
  37. raise self.error_str
  38. end
  39. self
  40. end
  41.  
  42. ## error
  43. "The 'AnetApi/xml/v1/schema/AnetApiSchema.xsd:customerPaymentProfileId' element is invalid - The value '' is invalid according to its datatype 'AnetApi/xml/v1/schema/AnetApiSchema.xsd:numericString' - The Pattern constraint failed."
Add Comment
Please, Sign In to add comment