Authorize.net CIM Rails implementation sample code
-
24-05-2021 - |
题
Authorize.net provides some sample code for using CIM with ruby but its uses XML. I am would like to do this with a more rails like method similar to the following AIM transaction code provided by authorize.net
transaction = AuthorizeNet::AIM::Transaction.new(API_LOGIN_ID, TRANSACTION_KEY, :gateway => :sandbox)
credit_card = AuthorizeNet::CreditCard.new('4111111111111111', '1120')
response = transaction.authorize(bid.amount, credit_card)
I have searched but cannot find any sample code. Can anyone please provide a link or some sample code to create a customer, store a creditcard, retrieve the customer and edit?
Thank you
解决方案
I found the ActiveMerchant gem it has a gateway to CIM.
其他提示
CIM API provides two formats: - XML calls - SOAP calls
I've show a simple example of SOAP call for creating a customer profiles via CIM api methods.I've used SAVON for making soap client.
1.Initialize savon client object with wsdl file for CIM service provided by gateway
client = Savon.client(wsdl: "https://apitest.authorize.net/soap/v1/Service.asmx?WSDL",ssl_verify_mode: :none)
- Make a call with transaction ID provided by gateway
response = client.call(:create_customer_profile,:message => {:merchantAuthentication => {"name" => "-----------","transactionKey" => '-----------'},:profile => {:email =>"arunsharmar321@gmail.com"} })
- Parse response as json output
JSON.parse((response.body).to_json)
Response output in json => {"create_customer_profile_response"=>{"create_customer_profile_result"=>{"result_code"=>"Ok", "messages"=>{"messages_type_message"=>{"code"=>"I00001", "text"=>"Successful."}}, "customer_profile_id"=>"36538428", "customer_payment_profile_id_list"=>nil, "customer_shipping_address_id_list"=>nil, "validation_direct_response_list"=>nil}, "@xmlns"=>"https://api.authorize.net/soap/v1/"}}