Skip to content

Instantly share code, notes, and snippets.

@supairish
Created June 26, 2013 23:09
Show Gist options
  • Save supairish/5872581 to your computer and use it in GitHub Desktop.
Save supairish/5872581 to your computer and use it in GitHub Desktop.
Paypal Payflowpro example
@secure_token_id = UUID.generate.gsub('-', '').slice(0, 25)
current_user.update_attribute(:paypal_token_id, @secure_token_id)
paypal_params = {'PARTNER' => 'PayPal', 'VENDOR' => PAYPAL_USER, 'USER' => PAYPAL_USER, \
'PWD' => PAYPAL_MANAGER_PASSWORD, 'TRXTYPE' => 'S', 'AMT' => cost, 'CREATESECURETOKEN' => 'Y', \
'SECURETOKENID' => @secure_token_id
}.to_param
paypal_params += "&RETURNURL=#{paypal_success_url}&ERRORURL=#{paypal_error_url}&SILENTPOSTURL=#{paypal_silent_post_url}&CANCELURL=#{subscribe_url}"
Rails.logger.warn 'PAYPAL TOKEN REQUEST PARAMS'
Rails.logger.warn paypal_params
# Pilot URL is for sandbox testing
# Hit api with secure_token_id to get secure token to allow transaction
if Rails.env.development?
paypal_response = %x[ curl https://pilot-payflowpro.paypal.com -kd "#{ paypal_params }" ]
else
paypal_response = %x[ curl https://payflowpro.paypal.com -kd "#{ paypal_params }" ]
end
Rails.logger.warn 'PAYPAL RESPONSE'
Rails.logger.warn paypal_response
parsed_response = Rack::Utils.parse_query(paypal_response)
Rails.logger.warn 'PARSED RESPONSE'
Rails.logger.warn parsed_response
if parsed_response['RESULT'] == "0"
# Pull out token to use in iframe url
@secure_token = parsed_response['SECURETOKEN']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment