This repository has been archived by the owner on Jul 5, 2023. It is now read-only.
forked from vinibaggio/braspag
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor Use ERB for render templates xml
- Loading branch information
Renato Elias
committed
Nov 14, 2012
1 parent
3676749
commit 5776fa5
Showing
11 changed files
with
462 additions
and
2,926 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
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
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 |
---|---|---|
@@ -1,99 +1,18 @@ | ||
module Braspag | ||
class Connection | ||
PROTECTED_CARD_MAPPING = { | ||
:request_id => "RequestId", | ||
:merchant_id => "MerchantKey", | ||
:customer_name => "CustomerName", | ||
:holder => "CardHolder", | ||
:card_number => "CardNumber", | ||
:expiration => "CardExpiration" | ||
} | ||
|
||
JUST_CLICK_MAPPING = { | ||
:request_id => "RequestId", | ||
:merchant_id => "MerchantKey", | ||
:customer_name => "CustomerName", | ||
:order_id => "OrderId", | ||
:amount => "Amount", | ||
:payment_method => "PaymentMethod", | ||
:number_installments => "NumberInstallments", | ||
:payment_type => "PaymentType", | ||
:just_click_key => "JustClickKey", | ||
:security_code => "SecurityCode" | ||
} | ||
|
||
|
||
# saves credit card in Braspag PCI Compliant | ||
def archive(credit_card, customer, request_id) | ||
|
||
self.check_protected_card_params(params) | ||
|
||
data = { 'saveCreditCardRequestWS' => {} } | ||
|
||
PROTECTED_CARD_MAPPING.each do |k, v| | ||
data['saveCreditCardRequestWS'][v] = params[k] || "" | ||
end | ||
|
||
|
||
client = Savon::Client.new(self.save_protected_card_url) | ||
response = client.request(:web, :save_credit_card) do | ||
soap.body = data | ||
end | ||
|
||
response.to_hash[:save_credit_card_response][:save_credit_card_result] | ||
|
||
year_normalize = credit_card.year.to_s[-2, 2] | ||
|
||
template = ERB.new 'save_credit' | ||
puts template.result(binding) | ||
end | ||
|
||
# request the credit card info in Braspag PCI Compliant | ||
def get_recurrency(credit_card) | ||
|
||
raise InvalidJustClickKey unless valid_just_click_key?(just_click_key) | ||
|
||
data = { 'getCreditCardRequestWS' => {:loja => connection.merchant_id, :justClickKey => just_click_key} } | ||
|
||
request = ::HTTPI::Request.new(self.get_protected_card_url) | ||
request.body = { 'getCreditCardRequestWS' => {:loja => connection.merchant_id, :justClickKey => just_click_key} } | ||
|
||
response = ::HTTPI.post(request) | ||
|
||
response = Utils::convert_to_map(response.body, { | ||
:holder => "CardHolder", | ||
:card_number => "CardNumber", | ||
:expiration => "CardExpiration", | ||
:masked_card_number => "MaskedCardNumber" | ||
}) | ||
|
||
raise UnknownError if response[:card_number].nil? | ||
response | ||
end | ||
|
||
def recurrency(order, credit_card, request_id) | ||
|
||
self.check_just_click_shop_params(params) | ||
|
||
order_id = params[:order_id] | ||
raise InvalidOrderId unless self.valid_order_id?(order_id) | ||
|
||
data = { 'justClickShopRequestWS' => {} } | ||
|
||
JUST_CLICK_MAPPING.each do |k, v| | ||
case k | ||
when :payment_method | ||
data['justClickShopRequestWS'][v] = Braspag::Connection.instance.homologation? ? PAYMENT_METHODS[:braspag] : PAYMENT_METHODS[params[:payment_method]] | ||
else | ||
data['justClickShopRequestWS'][v] = params[k] || "" | ||
end | ||
end | ||
|
||
client = Savon::Client.new(self.just_click_shop_url) | ||
response = client.request(:web, :just_click_shop) do | ||
soap.body = data | ||
end | ||
|
||
response.to_hash[:just_click_shop_response][:just_click_shop_result] | ||
|
||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope"> | ||
<env:Header /> | ||
<env:Body> | ||
<tns:DecryptRequest xmlns:tns="https://www.pagador.com.br/webservice/BraspagGeneralService"> | ||
<tns:merchantId><%= connection.merchant_id %></tns:merchantId> | ||
<tns:cryptString><%= encripted_text %></tns:cryptString> | ||
</tns:DecryptRequest> | ||
</env:Body> | ||
</env:Envelope> |
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,14 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope"> | ||
<env:Header /> | ||
<env:Body> | ||
<tns:EncryptRequest xmlns:tns="https://www.pagador.com.br/webservice/BraspagGeneralService"> | ||
<tns:merchantId><%= connection.merchant_id %></tns:merchantId> | ||
<tns:request> | ||
<% map.each do |key, value| %> | ||
<tns:string><%= key %>=<%= value %></tns:string> | ||
<% end %> | ||
</tns:request> | ||
</tns:EncryptRequest> | ||
</env:Body> | ||
</env:Envelope> |
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,16 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> | ||
<soap:Body> | ||
<SaveCreditCard xmlns="http://www.cartaoprotegido.com.br/WebService/"> | ||
<saveCreditCardRequestWS> | ||
<MerchantKey><%= merchant_id %></MerchantKey> | ||
<CustomerIdentification><%= customer.cpf%></CustomerIdentification> | ||
<CustomerName><%= customer.name %></CustomerName> | ||
<CardHolder><%= credit_card.holder_name %></CardHolder> | ||
<CardNumber><%= credit_card.number %></CardNumber> | ||
<CardExpiration><%= credit_card.year + credit_card.month %></CardExpiration> | ||
<JustClickAlias><%= creditcard_alias%></JustClickAlias> | ||
</saveCreditCardRequestWS> | ||
</SaveCreditCard> | ||
</soap:Body> | ||
</soap:Envelope> |
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 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> | ||
<soap:Body> | ||
<GetCreditCard xmlns="http://www.cartaoprotegido.com.br/WebService/"> | ||
<getCreditCardRequestWS> | ||
<MerchantKey><%= merchant_id %></MerchantKey> | ||
<JustClickKey>guid</JustClickKey> | ||
<JustClickAlias>string</JustClickAlias> | ||
</getCreditCardRequestWS> | ||
</GetCreditCard> | ||
</soap:Body> | ||
</soap:Envelope> |
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,23 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> | ||
<soap:Body> | ||
<JustClickShop xmlns="http://www.cartaoprotegido.com.br/WebService/"> | ||
<justClickShopRequestWS> | ||
<MerchantKey>guid</MerchantKey> | ||
<CustomerIdentification>string</CustomerIdentification> | ||
<CustomerName>string</CustomerName> | ||
<OrderId>string</OrderId> | ||
<Amount>int</Amount> | ||
<PaymentMethod>short</PaymentMethod> | ||
<NumberInstallments>short</NumberInstallments> | ||
<PaymentType>short</PaymentType> | ||
<JustClickKey>guid</JustClickKey> | ||
<SecurityCode>string</SecurityCode> | ||
<Country>string</Country> | ||
<Currency>string</Currency> | ||
<MerchantIdPagador>guid</MerchantIdPagador> | ||
<JustClickAlias>string</JustClickAlias> | ||
</justClickShopRequestWS> | ||
</JustClickShop> | ||
</soap:Body> | ||
</soap:Envelope> |
Oops, something went wrong.