Module: RailsTrade::PaymentType::Paypal
- Defined in:
- app/models/rails_trade/payment_type/paypal.rb
Instance Method Summary collapse
- #paypal_execute(params) ⇒ Object
- #paypal_items_params ⇒ Object
- #paypal_params ⇒ Object
- #paypal_prepay ⇒ Object
- #paypal_result ⇒ Object
Instance Method Details
#paypal_execute(params) ⇒ Object
15 16 17 18 19 20 21 |
# File 'app/models/rails_trade/payment_type/paypal.rb', line 15 def paypal_execute(params) return unless self.payment_id paypal_payment = PayPal::SDK::REST::DataTypes::Payment.find(self.payment_id) paypal_payment.execute(payer_id: params[:PayerID]) paypal_record(paypal_payment) end |
#paypal_items_params ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'app/models/rails_trade/payment_type/paypal.rb', line 60 def paypal_items_params items = order_items.map do |item| { name: item.good.name, sku: item.good.sku, price: item.good.price.to_money.exchange_to(self.currency).to_s, currency: self.currency.upcase, quantity: item.number } end serves = order_serves.map do |item| { name: item.serve.name, sku: item.serve.id, price: item.price.to_money.exchange_to(self.currency).to_s, currency: self.currency.upcase, quantity: 1 } end items + serves end |
#paypal_params ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'app/models/rails_trade/payment_type/paypal.rb', line 37 def paypal_params { intent: 'sale', payer: { payment_method: 'paypal' }, redirect_urls: { return_url: url_helpers.paypal_execute_my_order_url(self.id), cancel_url: url_helpers.cancel_my_order_url(self.id) }, transactions: { item_list: { items: paypal_items_params }, amount: { total: self.unreceived_amount, currency: self.currency.upcase }, description: '' } } end |
#paypal_prepay ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 |
# File 'app/models/rails_trade/payment_type/paypal.rb', line 3 def paypal_prepay paypal_payment = PayPal::SDK::REST::DataTypes::Payment.new(paypal_params) result = paypal_payment.create if result self.update(payment_id: paypal_payment.id) else self.errors.add :payment_id, paypal_payment.error.inspect end paypal_payment.links.find{ |v| v.rel == 'approval_url' }.href end |
#paypal_result ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'app/models/rails_trade/payment_type/paypal.rb', line 23 def paypal_result return self if self.payment_status == 'all_paid' return unless self.payment_id paypal_payment ||= PayPal::SDK::REST::DataTypes::Payment.find(self.payment_id) trans = paypal_payment.transactions[0] if paypal_payment.state == 'approved' self.change_to_paid! type: 'PaypalPayment', payment_uuid: trans.[0].sale.id, params: trans else errors.add :base, paypal_payment.error.inspect end end |