-
Notifications
You must be signed in to change notification settings - Fork 177
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated to supported latest edge PaymentMethods (very edge)
- Loading branch information
Showing
9 changed files
with
166 additions
and
66 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
class PaypalAccount < ActiveRecord::Base | ||
has_many :payments, :as => :source | ||
|
||
def finalize!(payment) | ||
authorization = find_authorization | ||
|
||
ppx_response = p.payment_method.capture((100 * payment.amount).to_i, authorization.transaction_id) | ||
if ppx_response.success? | ||
payment = authorization.paypal_payment | ||
|
||
transaction = PaypalTxn.new(:payment => payment, | ||
:amount => ppx_response.params["gross_amount"].to_f, | ||
:message => ppx_response.params["message"], | ||
:payment_status => ppx_response.params["payment_status"], | ||
:pending_reason => ppx_response.params["pending_reason"], | ||
:transaction_id => ppx_response.params["transaction_id"], | ||
:transaction_type => ppx_response.params["transaction_type"], | ||
:payment_type => ppx_response.params["payment_type"], | ||
:ack => ppx_response.params["ack"], | ||
:token => ppx_response.params["token"], | ||
:avs_response => ppx_response.avs_result["code"], | ||
:cvv_response => ppx_response.cvv_result["code"]) | ||
|
||
payment.paypal_txns << transaction | ||
|
||
payment.save | ||
else | ||
gateway_error(ppx_response) | ||
end | ||
|
||
|
||
end | ||
|
||
|
||
private | ||
def find_authorization(payment) | ||
#find the transaction associated with the original authorization/capture | ||
txns.find(:first, | ||
:conditions => {:pending_reason => "authorization", :payment_status => "Pending"}, | ||
:order => 'created_at DESC') | ||
end | ||
|
||
def find_capture(payment) | ||
#find the transaction associated with the original authorization/capture | ||
txns.find(:first, | ||
:conditions => {:payment_status => "Completed"}, | ||
:order => 'created_at DESC') | ||
end | ||
|
||
def can_capture?(payment) | ||
find_capture.nil? | ||
end | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
class PaypalTxn < ActiveRecord::Base | ||
belongs_to :paypal_payment | ||
class PaypalTxn < Transaction | ||
enumerable_constant :txn_type, :constants => [:authorize, :capture, :purchase, :void, :credit] | ||
|
||
def txn_type_name | ||
TxnType.from_value(txn_type) | ||
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,3 @@ | ||
<a href="<%= paypal_payment_order_checkout_url @order, :payment_method_id => payment_method %>" style="text-align: center;"> | ||
<img src="https://www.paypal.com/en_US/i/btn/btn_xpressCheckout.gif" align="left" style="margin-right:7px;"/> | ||
</a> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
class CreatePaypalAccounts < ActiveRecord::Migration | ||
def self.up | ||
create_table :paypal_accounts do |t| | ||
t.string :email | ||
t.string :payer_id | ||
t.string :payer_country | ||
t.string :payer_status | ||
end | ||
end | ||
|
||
def self.down | ||
drop_table :paypal_accounts | ||
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,26 @@ | ||
class MakePaypalTxnSti < ActiveRecord::Migration | ||
def self.up | ||
add_column :transactions, :payment_status, :string | ||
add_column :transactions, :message, :string | ||
add_column :transactions, :pending_reason, :string | ||
add_column :transactions, :transaction_id, :string | ||
add_column :transactions, :transaction_type, :string | ||
add_column :transactions, :payment_type, :string | ||
add_column :transactions, :token, :string | ||
|
||
#to-do migrate existing ppx_txns | ||
|
||
drop_table :paypal_txns | ||
|
||
end | ||
|
||
def self.down | ||
remove_column :transactions, :payment_status | ||
remove_column :transactions, :message | ||
remove_column :transactions, :pending_reason | ||
remove_column :transactions, :transaction_id | ||
remove_column :transactions, :transaction_type | ||
remove_column :transactions, :payment_type | ||
remove_column :transactions, :token | ||
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