Method: AuthorizeNet::Api#chargeAndCreateProfile
- Defined in:
- lib/authorize_net/api.rb
#chargeAndCreateProfile(amount, customer_profile) ⇒ customer_profile_id, payment_profile_id
Creates the CustomerProfile and charges the first listed PaymentProfile on AuthorizeNet
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/authorize_net/api.rb', line 63 def chargeAndCreateProfile(amount, customer_profile) if customer_profile.payment_profiles.empty? raise "[AuthorizeNet] CustomerProfile in Api.chargeAndCreateProfile requires a PaymentProfile" end payment_profile = customer_profile.payment_profiles.first xml_obj = getXmlAuth xml_obj["transactionRequest"] = { "transactionType" => "authCaptureTransaction", "amount" => amount, "payment" => { "creditCard" => payment_profile.credit_card.to_h, }, "profile" => { "createProfile" => true, }, "customer" => { "id" => customer_profile.merchant_id, "email" => customer_profile.email, "description" => customer_profile.description, }, "billTo" => payment_profile.billing_address.to_h, } response = sendRequest("createTransactionRequest", xml_obj) validate_hash(response, amount, use_api_login: true) if !response.nil? return { :transaction => AuthorizeNet::Transaction.parse(response), :customer_profile_id => AuthorizeNet::Util.getXmlValue( response, "customerProfileId"), :payment_profile_id => AuthorizeNet::Util.getXmlValue( response, "customerPaymentProfileIdList numericString"), } end end |