-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
THREESCALE-11011: Authorize.net is a living dead 🧟♀️ (#3771)
- Loading branch information
Showing
45 changed files
with
889 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
|
||
// I'm comming back to this. | ||
|
||
|
||
// var Payment = { | ||
// | ||
// init: function(card_type) { | ||
// // if(card_type) | ||
// this.showCards(card_type); | ||
// }, | ||
// | ||
// showCards: function() { | ||
// | ||
// // $$('#supported_cardtypes ul').invoke('hide'); | ||
// $('supported_cardtypes').show(); | ||
// // $(card).show(); | ||
// }, | ||
// | ||
// listen: function(){ | ||
// $('account_payment_gateway_type').observe() | ||
// } | ||
// | ||
// } | ||
|
||
// Payment.SupportedCards = { | ||
// 'authorize_net' : ['visa', 'master', 'american_express', 'discover'], | ||
// 'braintree' : ['visa', 'master', 'american_express', 'discover'] | ||
// } | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
# frozen_string_literal: true | ||
|
||
module PaymentGateways | ||
class AuthorizeNetCimCrypt < PaymentGatewayCrypt | ||
|
||
def authorize_api_url | ||
::ActiveMerchant::Billing::AuthorizeNetCimGateway.public_send(test? ? :test_url : :live_url) | ||
end | ||
|
||
def form_url | ||
@form_url ||= "https://#{test? ? 'test' : 'secure'}.authorize.net/profile" | ||
end | ||
|
||
def create_profile | ||
log_gateway_action("Creating Profile") | ||
|
||
response = create_remote_profile | ||
account.credit_card_auth_code = response.params['customer_profile_id'] | ||
account.save! | ||
log_gateway_action("Creating Profile ok") | ||
end | ||
|
||
def action_form_url | ||
action = account.credit_card_stored? ? "/editPayment" : "/addPayment" | ||
form_url + action | ||
end | ||
|
||
def payment_profile | ||
auth_response = provider.payment_gateway.cim_gateway | ||
.get_customer_profile(:customer_profile_id => account.credit_card_auth_code) | ||
return unless has_credit_card?(auth_response) | ||
auth_response.params['profile']['payment_profiles']['customer_payment_profile_id'] | ||
end | ||
|
||
def has_credit_card?(auth_response) | ||
auth_response.success? && | ||
auth_response.params['profile'].key?('payment_profiles') && | ||
auth_response.params['profile']['payment_profiles'].key?('payment') && | ||
auth_response.params['profile']['payment_profiles']['payment'].key?('credit_card') | ||
end | ||
|
||
def get_token(args) | ||
getHostedProfilePageRequest = <<~EOR | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<getHostedProfilePageRequest xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd"> | ||
<merchantAuthentication> | ||
<name>#{args[:login]}</name> | ||
<transactionKey>#{args[:trans_key]}</transactionKey> | ||
</merchantAuthentication> | ||
<customerProfileId>#{args[:profile_id]}</customerProfileId> | ||
<hostedProfileSettings> | ||
<setting> | ||
<settingName>hostedProfileReturnUrl</settingName> | ||
<settingValue>#{args[:ok_url]}</settingValue> | ||
</setting> | ||
<setting> | ||
<settingName>hostedProfileReturnUrlText</settingName> | ||
<settingValue>Continue to settings</settingValue> | ||
</setting> | ||
<setting> | ||
<settingName>hostedProfilePageBorderVisible</settingName> | ||
<settingValue>true</settingValue> | ||
</setting> | ||
</hostedProfileSettings> | ||
</getHostedProfilePageRequest> | ||
EOR | ||
|
||
begin | ||
log_gateway_action("Getting token for user #{user.id}") | ||
crypted_request = RestClient.post authorize_api_url, getHostedProfilePageRequest, | ||
:content_type => "text/xml" | ||
|
||
xml_reply = Nokogiri::XML::Document.parse(crypted_request) | ||
if xml_reply.xpath("//api:resultCode", | ||
'api' => 'AnetApi/xml/v1/schema/AnetApiSchema.xsd').text == 'Ok' | ||
return xml_reply.xpath("//api:token", 'api' => 'AnetApi/xml/v1/schema/AnetApiSchema.xsd').text | ||
else | ||
notify_exception(IncorrectKeys.new(xml_reply)) | ||
code=xml_reply.xpath("//api:code", 'api' => 'AnetApi/xml/v1/schema/AnetApiSchema.xsd').text | ||
raise IncorrectKeys, "code:#{code}." | ||
end | ||
log_gateway_action("user #{user.id} token aquired") | ||
rescue SocketError => e | ||
notify_exception(e) | ||
raise PaymentGatewayDown, "Payment gateway offline. Try again in few minutes" | ||
end | ||
|
||
end | ||
|
||
def update_user(auth_response) | ||
return :error unless auth_response.params['messages']['result_code'] == 'Ok' | ||
|
||
log_gateway_action("updating user #{user}") | ||
payment_profiles = auth_response.params['profile']['payment_profiles'] | ||
if payment_profiles && payment_profiles['bill_to'] | ||
bill_info = payment_profiles['bill_to'] | ||
account.billing_address_name = bill_info['company'] | ||
account.billing_address_address1 = bill_info['address'] | ||
account.billing_address_city = bill_info['city'] | ||
account.billing_address_country = bill_info['country'] | ||
account.billing_address_state = bill_info['state'] | ||
account.billing_address_zip = bill_info['zip'] | ||
account.billing_address_phone = bill_info['phone_number'] | ||
end | ||
|
||
account.credit_card_partial_number = | ||
auth_response.params['profile']['payment_profiles']['payment']['credit_card']['card_number'][-4..-1] | ||
account.credit_card_authorize_net_payment_profile_token = | ||
auth_response.params['profile']['payment_profiles']['customer_payment_profile_id'] | ||
account.credit_card_expires_on = nil #We can't store expiration date as Authorize.net doesn't retrieve it | ||
account.save! | ||
end | ||
|
||
# FIXME: delete_user_profile has nothing to do in this class | ||
# Reusing Account#delete_cc_details | ||
def delete_user_profile | ||
account.delete_cc_details | ||
account.save! | ||
end | ||
|
||
private | ||
|
||
def create_remote_profile | ||
response = provider.payment_gateway.cim_gateway | ||
.create_customer_profile(profile: { email: user.email, description: buyer_reference }) | ||
|
||
# this is a nice trick, where we raise IncorectKeys whatever the response was | ||
raise IncorrectKeys, response unless response.params['messages']['result_code'] == 'Ok' | ||
response | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<form class="form-horizontal" method="post" action="<%= @form_url %>" id="formAuthorizeNetPage"> | ||
<input type="hidden" name="Token" value="<%= @token %>" /> | ||
<input type="hidden" name="PaymentProfileId" value="<%= @payment_profile_id %>" /> | ||
|
||
<fieldset> | ||
<div class="form-group"> | ||
<div class="col-md-10 operations"> | ||
<input class="btn btn-primary pull-right" type="submit" onclick="document.getElementById('formAuthorizeNetPage').submit();" value="<%= text -%>" /> | ||
</div> | ||
</div> | ||
</fieldset> | ||
</form> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 0 additions & 5 deletions
5
db/migrate/20240229072029_remove_authorize_net_c_ctoken_from_account.rb
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.