rails_trade 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +165 -0
- data/README.md +47 -0
- data/Rakefile +37 -0
- data/app/assets/config/rails_trade_manifest.js +1 -0
- data/app/assets/javascripts/controllers/rails_trade_admin/buyers/index.js +15 -0
- data/app/assets/javascripts/controllers/rails_trade_admin/buyers/overdue.js +15 -0
- data/app/assets/javascripts/controllers/rails_trade_admin/cart_items/create.js +3 -0
- data/app/assets/javascripts/controllers/rails_trade_admin/cart_items/index.js +80 -0
- data/app/assets/javascripts/controllers/rails_trade_admin/cart_items/only.js +45 -0
- data/app/assets/javascripts/controllers/rails_trade_admin/orders/new.js +29 -0
- data/app/assets/javascripts/controllers/rails_trade_admin/payment_methods/edit.js +1 -0
- data/app/assets/javascripts/controllers/rails_trade_admin/payment_methods/index.js +1 -0
- data/app/assets/javascripts/controllers/rails_trade_admin/payment_methods/new.js +1 -0
- data/app/assets/javascripts/controllers/rails_trade_admin/payment_methods/unverified.js +1 -0
- data/app/assets/javascripts/controllers/rails_trade_admin/payments/index.js +0 -0
- data/app/assets/javascripts/controllers/rails_trade_admin/payments/new.js +1 -0
- data/app/assets/javascripts/controllers/rails_trade_admin/promote_buyers/edit.js +31 -0
- data/app/assets/javascripts/controllers/rails_trade_admin/promote_buyers/new.js +31 -0
- data/app/assets/javascripts/controllers/rails_trade_admin/promote_goods/index.js +1 -0
- data/app/assets/javascripts/controllers/rails_trade_admin/promotes/edit.js +2 -0
- data/app/assets/javascripts/controllers/rails_trade_admin/promotes/index.js +1 -0
- data/app/assets/javascripts/controllers/rails_trade_admin/promotes/new.js +2 -0
- data/app/assets/javascripts/controllers/rails_trade_admin/serves/edit.js +2 -0
- data/app/assets/javascripts/controllers/rails_trade_admin/serves/index.js +1 -0
- data/app/assets/javascripts/controllers/rails_trade_admin/serves/new.js +4 -0
- data/app/assets/javascripts/controllers/rails_trade_my/cart_items/create.js +3 -0
- data/app/assets/javascripts/controllers/rails_trade_my/cart_items/index.js +65 -0
- data/app/controllers/areas_controller.rb +18 -0
- data/app/controllers/buyers_controller.rb +8 -0
- data/app/controllers/concerns/controller_order_types.rb +92 -0
- data/app/controllers/goods_controller.rb +90 -0
- data/app/controllers/payments_controller.rb +50 -0
- data/app/controllers/providers_controller.rb +8 -0
- data/app/controllers/the_trade_admin/addresses_controller.rb +75 -0
- data/app/controllers/the_trade_admin/areas_controller.rb +50 -0
- data/app/controllers/the_trade_admin/base_controller.rb +5 -0
- data/app/controllers/the_trade_admin/buyers_controller.rb +37 -0
- data/app/controllers/the_trade_admin/cart_item_serves_controller.rb +63 -0
- data/app/controllers/the_trade_admin/cart_items_controller.rb +123 -0
- data/app/controllers/the_trade_admin/order_payments_controller.rb +52 -0
- data/app/controllers/the_trade_admin/orders_controller.rb +103 -0
- data/app/controllers/the_trade_admin/payment_methods_controller.rb +111 -0
- data/app/controllers/the_trade_admin/payment_orders_controller.rb +56 -0
- data/app/controllers/the_trade_admin/payment_references_controller.rb +54 -0
- data/app/controllers/the_trade_admin/payment_strategies_controller.rb +50 -0
- data/app/controllers/the_trade_admin/payments_controller.rb +89 -0
- data/app/controllers/the_trade_admin/produces_controller.rb +66 -0
- data/app/controllers/the_trade_admin/promote_buyers_controller.rb +39 -0
- data/app/controllers/the_trade_admin/promote_charges_controller.rb +62 -0
- data/app/controllers/the_trade_admin/promote_goods_controller.rb +50 -0
- data/app/controllers/the_trade_admin/promotes_controller.rb +105 -0
- data/app/controllers/the_trade_admin/providers_controller.rb +121 -0
- data/app/controllers/the_trade_admin/refunds_controller.rb +60 -0
- data/app/controllers/the_trade_admin/serve_charges_controller.rb +67 -0
- data/app/controllers/the_trade_admin/serves_controller.rb +107 -0
- data/app/controllers/the_trade_my/addresses_controller.rb +50 -0
- data/app/controllers/the_trade_my/base_controller.rb +13 -0
- data/app/controllers/the_trade_my/buyers_controller.rb +35 -0
- data/app/controllers/the_trade_my/cart_items_controller.rb +71 -0
- data/app/controllers/the_trade_my/order_items_controller.rb +49 -0
- data/app/controllers/the_trade_my/orders_controller.rb +161 -0
- data/app/controllers/the_trade_my/payment_methods_controller.rb +76 -0
- data/app/controllers/the_trade_my/providers_controller.rb +44 -0
- data/app/models/rails_trade/address.rb +14 -0
- data/app/models/rails_trade/area.rb +65 -0
- data/app/models/rails_trade/cart_item.rb +185 -0
- data/app/models/rails_trade/cart_item_serve.rb +16 -0
- data/app/models/rails_trade/concerns/good_able.rb +63 -0
- data/app/models/rails_trade/concerns/order_able.rb +48 -0
- data/app/models/rails_trade/concerns/promote_fee.rb +54 -0
- data/app/models/rails_trade/concerns/serve_fee.rb +41 -0
- data/app/models/rails_trade/concerns/summary_service.rb +67 -0
- data/app/models/rails_trade/concerns/the_payment.rb +88 -0
- data/app/models/rails_trade/concerns/the_refund.rb +36 -0
- data/app/models/rails_trade/concerns/the_trade_buyer.rb +50 -0
- data/app/models/rails_trade/concerns/the_trade_user.rb +23 -0
- data/app/models/rails_trade/good_partner.rb +8 -0
- data/app/models/rails_trade/good_produce.rb +14 -0
- data/app/models/rails_trade/order.rb +111 -0
- data/app/models/rails_trade/order_item.rb +88 -0
- data/app/models/rails_trade/order_promote.rb +23 -0
- data/app/models/rails_trade/order_serve.rb +23 -0
- data/app/models/rails_trade/order_shipment.rb +10 -0
- data/app/models/rails_trade/payment.rb +135 -0
- data/app/models/rails_trade/payment_interface/payment_interface_base.rb +8 -0
- data/app/models/rails_trade/payment_interface/the_alipay.rb +49 -0
- data/app/models/rails_trade/payment_interface/the_paypal.rb +103 -0
- data/app/models/rails_trade/payment_interface/the_stripe.rb +73 -0
- data/app/models/rails_trade/payment_interface/the_wxpay.rb +56 -0
- data/app/models/rails_trade/payment_method.rb +57 -0
- data/app/models/rails_trade/payment_methods/alipay_method.rb +7 -0
- data/app/models/rails_trade/payment_methods/bank_method.rb +7 -0
- data/app/models/rails_trade/payment_methods/stripe_method.rb +57 -0
- data/app/models/rails_trade/payment_order.rb +75 -0
- data/app/models/rails_trade/payment_reference.rb +15 -0
- data/app/models/rails_trade/payment_strategy.rb +16 -0
- data/app/models/rails_trade/payments/alipay_payment.rb +12 -0
- data/app/models/rails_trade/payments/bank_payment.rb +15 -0
- data/app/models/rails_trade/payments/hand_payment.rb +13 -0
- data/app/models/rails_trade/payments/paypal_payment.rb +8 -0
- data/app/models/rails_trade/payments/stripe_payment.rb +7 -0
- data/app/models/rails_trade/payments/wxpay_payment.rb +14 -0
- data/app/models/rails_trade/produce.rb +18 -0
- data/app/models/rails_trade/promote.rb +40 -0
- data/app/models/rails_trade/promote_buyer.rb +9 -0
- data/app/models/rails_trade/promote_charge.rb +17 -0
- data/app/models/rails_trade/promote_charges/single_promote_charge.rb +7 -0
- data/app/models/rails_trade/promote_charges/total_promote_charge.rb +7 -0
- data/app/models/rails_trade/promote_good.rb +9 -0
- data/app/models/rails_trade/promotes/amount_promote.rb +4 -0
- data/app/models/rails_trade/promotes/number_promote.rb +4 -0
- data/app/models/rails_trade/provider.rb +25 -0
- data/app/models/rails_trade/refund.rb +63 -0
- data/app/models/rails_trade/refunds/alipay_refund.rb +33 -0
- data/app/models/rails_trade/refunds/bank_refund.rb +5 -0
- data/app/models/rails_trade/refunds/hand_refund.rb +5 -0
- data/app/models/rails_trade/refunds/paypal_refund.rb +32 -0
- data/app/models/rails_trade/refunds/stripe_refund.rb +26 -0
- data/app/models/rails_trade/refunds/wxpay_refund.rb +40 -0
- data/app/models/rails_trade/serve.rb +44 -0
- data/app/models/rails_trade/serve_charge.rb +37 -0
- data/app/models/rails_trade/serve_charges/single_serve_charge.rb +7 -0
- data/app/models/rails_trade/serve_charges/total_serve_charge.rb +7 -0
- data/app/models/rails_trade/serve_good.rb +9 -0
- data/app/models/rails_trade/serves/number_serve.rb +4 -0
- data/app/models/rails_trade/serves/quantity_serve.rb +4 -0
- data/app/models/rails_trade/shipment.rb +8 -0
- data/app/views/buyers/_show.html.erb +7 -0
- data/app/views/buyers/show.js.erb +1 -0
- data/app/views/goods/_choose.html.erb +36 -0
- data/app/views/goods/_good.html.erb +17 -0
- data/app/views/goods/_good_item.html.erb +17 -0
- data/app/views/goods/_nav.html.erb +18 -0
- data/app/views/goods/_search.html.erb +6 -0
- data/app/views/goods/index.html.erb +34 -0
- data/app/views/goods/index/_product.html.erb +14 -0
- data/app/views/goods/item.html.erb +47 -0
- data/app/views/goods/produce.html.erb +48 -0
- data/app/views/goods/show.html.erb +2 -0
- data/app/views/goods/show/_basic.html.erb +23 -0
- data/app/views/goods/show/_carousel.html.erb +35 -0
- data/app/views/goods/show/_items.html.erb +32 -0
- data/app/views/goods/show/_sales.html.erb +17 -0
- data/app/views/goods/show/_side.html.erb +19 -0
- data/app/views/goods/taxon/_breadcrumb.html.erb +8 -0
- data/app/views/goods/taxon/_nav.html.erb +19 -0
- data/app/views/goods/taxon/_nav_.html.erb +18 -0
- data/app/views/goods/taxon/_nav_last.html.erb +19 -0
- data/app/views/layouts/rails_trade_admin/base.html.erb +25 -0
- data/app/views/layouts/rails_trade_my/base.html.erb +28 -0
- data/app/views/rails_trade_admin/addresses/_address.html.erb +24 -0
- data/app/views/rails_trade_admin/addresses/_edit.html.erb +13 -0
- data/app/views/rails_trade_admin/addresses/_form.html.erb +23 -0
- data/app/views/rails_trade_admin/addresses/_new.html.erb +13 -0
- data/app/views/rails_trade_admin/addresses/create.js.erb +2 -0
- data/app/views/rails_trade_admin/addresses/destroy.js.erb +1 -0
- data/app/views/rails_trade_admin/addresses/edit.js.erb +39 -0
- data/app/views/rails_trade_admin/addresses/index.html.erb +41 -0
- data/app/views/rails_trade_admin/addresses/new.js.erb +52 -0
- data/app/views/rails_trade_admin/addresses/show.html.erb +4 -0
- data/app/views/rails_trade_admin/addresses/update.js.erb +2 -0
- data/app/views/rails_trade_admin/areas/_form.html.erb +9 -0
- data/app/views/rails_trade_admin/areas/edit.html.erb +16 -0
- data/app/views/rails_trade_admin/areas/index.html.erb +43 -0
- data/app/views/rails_trade_admin/areas/new.html.erb +11 -0
- data/app/views/rails_trade_admin/areas/show.html.erb +1 -0
- data/app/views/rails_trade_admin/base/_nav.html.erb +24 -0
- data/app/views/rails_trade_admin/base/_nav_bar.html.erb +23 -0
- data/app/views/rails_trade_admin/base/_nav_payment.html.erb +25 -0
- data/app/views/rails_trade_admin/buyers/_form.html.erb +17 -0
- data/app/views/rails_trade_admin/buyers/_menu.html.erb +5 -0
- data/app/views/rails_trade_admin/buyers/_search_form.html.erb +11 -0
- data/app/views/rails_trade_admin/buyers/edit.html.erb +6 -0
- data/app/views/rails_trade_admin/buyers/index.html.erb +46 -0
- data/app/views/rails_trade_admin/buyers/new.html.erb +5 -0
- data/app/views/rails_trade_admin/buyers/orders.html.erb +134 -0
- data/app/views/rails_trade_admin/buyers/overdue.html.erb +49 -0
- data/app/views/rails_trade_admin/buyers/show.html.erb +4 -0
- data/app/views/rails_trade_admin/cart_item_serves/_check.html.erb +12 -0
- data/app/views/rails_trade_admin/cart_item_serves/_index.html.erb +37 -0
- data/app/views/rails_trade_admin/cart_item_serves/_new.html.erb +14 -0
- data/app/views/rails_trade_admin/cart_item_serves/_serve.html.erb +16 -0
- data/app/views/rails_trade_admin/cart_item_serves/_single.html.erb +10 -0
- data/app/views/rails_trade_admin/cart_item_serves/_single_table.html.erb +29 -0
- data/app/views/rails_trade_admin/cart_item_serves/_total.html.erb +10 -0
- data/app/views/rails_trade_admin/cart_item_serves/_total_table.html.erb +26 -0
- data/app/views/rails_trade_admin/cart_item_serves/add.js.erb +47 -0
- data/app/views/rails_trade_admin/cart_item_serves/create.js.erb +3 -0
- data/app/views/rails_trade_admin/cart_item_serves/destroy.js.erb +50 -0
- data/app/views/rails_trade_admin/cart_item_serves/index.js.erb +50 -0
- data/app/views/rails_trade_admin/cart_item_serves/new.js.erb +5 -0
- data/app/views/rails_trade_admin/cart_item_serves/single.js.erb +55 -0
- data/app/views/rails_trade_admin/cart_item_serves/total.js.erb +55 -0
- data/app/views/rails_trade_admin/cart_items/_additions.html.erb +20 -0
- data/app/views/rails_trade_admin/cart_items/_filter.html.erb +15 -0
- data/app/views/rails_trade_admin/cart_items/_good_price.html.erb +10 -0
- data/app/views/rails_trade_admin/cart_items/_order_price.html.erb +27 -0
- data/app/views/rails_trade_admin/cart_items/_retail_price.html.erb +4 -0
- data/app/views/rails_trade_admin/cart_items/_single_price.html.erb +28 -0
- data/app/views/rails_trade_admin/cart_items/_total_price.html.erb +9 -0
- data/app/views/rails_trade_admin/cart_items/destroy.js.erb +1 -0
- data/app/views/rails_trade_admin/cart_items/error.html.erb +3 -0
- data/app/views/rails_trade_admin/cart_items/index.html.erb +104 -0
- data/app/views/rails_trade_admin/cart_items/only.html.erb +72 -0
- data/app/views/rails_trade_admin/cart_items/total.js.erb +11 -0
- data/app/views/rails_trade_admin/cart_items/update.js.erb +11 -0
- data/app/views/rails_trade_admin/goods/_form.html.erb +7 -0
- data/app/views/rails_trade_admin/goods/_item.html.erb +6 -0
- data/app/views/rails_trade_admin/goods/_new.html.erb +11 -0
- data/app/views/rails_trade_admin/goods/_show.html.erb +24 -0
- data/app/views/rails_trade_admin/goods/_show_tr.html.erb +24 -0
- data/app/views/rails_trade_admin/goods/create.js.erb +2 -0
- data/app/views/rails_trade_admin/goods/destroy.js.erb +1 -0
- data/app/views/rails_trade_admin/goods/edit.html.erb +16 -0
- data/app/views/rails_trade_admin/goods/edit.js.erb +8 -0
- data/app/views/rails_trade_admin/goods/edit_items.html.erb +43 -0
- data/app/views/rails_trade_admin/goods/edit_pic.html.erb +32 -0
- data/app/views/rails_trade_admin/goods/edit_promote.html.erb +64 -0
- data/app/views/rails_trade_admin/goods/index.html.erb +32 -0
- data/app/views/rails_trade_admin/goods/new.html.erb +14 -0
- data/app/views/rails_trade_admin/goods/new.js.erb +8 -0
- data/app/views/rails_trade_admin/goods/show.js.erb +5 -0
- data/app/views/rails_trade_admin/goods/update.js.erb +2 -0
- data/app/views/rails_trade_admin/order_payments/_index.html.erb +44 -0
- data/app/views/rails_trade_admin/order_payments/_new.html.erb +44 -0
- data/app/views/rails_trade_admin/order_payments/_payment_orders.html.erb +17 -0
- data/app/views/rails_trade_admin/order_payments/_payments.html.erb +19 -0
- data/app/views/rails_trade_admin/order_payments/create.js.erb +2 -0
- data/app/views/rails_trade_admin/order_payments/create_fail.js.erb +1 -0
- data/app/views/rails_trade_admin/order_payments/destroy.js.erb +2 -0
- data/app/views/rails_trade_admin/order_payments/index.js.erb +8 -0
- data/app/views/rails_trade_admin/order_payments/new.js.erb +8 -0
- data/app/views/rails_trade_admin/orders/_addresses.html.erb +36 -0
- data/app/views/rails_trade_admin/orders/_filter.html.erb +20 -0
- data/app/views/rails_trade_admin/orders/_form.html.erb +17 -0
- data/app/views/rails_trade_admin/orders/_invoice_addresses.html.erb +36 -0
- data/app/views/rails_trade_admin/orders/_item.html.erb +10 -0
- data/app/views/rails_trade_admin/orders/_new_items.html.erb +70 -0
- data/app/views/rails_trade_admin/orders/_search_form.html.erb +7 -0
- data/app/views/rails_trade_admin/orders/edit.html.erb +1 -0
- data/app/views/rails_trade_admin/orders/index.html.erb +61 -0
- data/app/views/rails_trade_admin/orders/new.html.erb +23 -0
- data/app/views/rails_trade_admin/orders/payments.html.erb +50 -0
- data/app/views/rails_trade_admin/orders/refresh.js.erb +7 -0
- data/app/views/rails_trade_admin/orders/show.html.erb +89 -0
- data/app/views/rails_trade_admin/payment_methods/_edit.html.erb +6 -0
- data/app/views/rails_trade_admin/payment_methods/_form.html.erb +5 -0
- data/app/views/rails_trade_admin/payment_methods/_index_layout.html.erb +15 -0
- data/app/views/rails_trade_admin/payment_methods/_new.html.erb +13 -0
- data/app/views/rails_trade_admin/payment_methods/_payment_method.html.erb +25 -0
- data/app/views/rails_trade_admin/payment_methods/_search_form.html.erb +22 -0
- data/app/views/rails_trade_admin/payment_methods/create.js.erb +2 -0
- data/app/views/rails_trade_admin/payment_methods/destroy.js.erb +1 -0
- data/app/views/rails_trade_admin/payment_methods/edit.html.erb +15 -0
- data/app/views/rails_trade_admin/payment_methods/edit.js.erb +8 -0
- data/app/views/rails_trade_admin/payment_methods/index.html.erb +23 -0
- data/app/views/rails_trade_admin/payment_methods/mine.html.erb +23 -0
- data/app/views/rails_trade_admin/payment_methods/new.html.erb +15 -0
- data/app/views/rails_trade_admin/payment_methods/new.js.erb +7 -0
- data/app/views/rails_trade_admin/payment_methods/unverified.html.erb +60 -0
- data/app/views/rails_trade_admin/payment_methods/update.js.erb +2 -0
- data/app/views/rails_trade_admin/payment_orders/_index.html.erb +31 -0
- data/app/views/rails_trade_admin/payment_orders/_new.html.erb +24 -0
- data/app/views/rails_trade_admin/payment_orders/_orders.html.erb +27 -0
- data/app/views/rails_trade_admin/payment_orders/cancel.js.erb +2 -0
- data/app/views/rails_trade_admin/payment_orders/create.js.erb +2 -0
- data/app/views/rails_trade_admin/payment_orders/create_fail.js.erb +1 -0
- data/app/views/rails_trade_admin/payment_orders/new.js.erb +6 -0
- data/app/views/rails_trade_admin/payment_orders/raise_fail.js.erb +1 -0
- data/app/views/rails_trade_admin/payment_orders/update.js.erb +2 -0
- data/app/views/rails_trade_admin/payment_orders/update_fail.js.erb +2 -0
- data/app/views/rails_trade_admin/payment_references/_form.html.erb +20 -0
- data/app/views/rails_trade_admin/payment_references/_new.html.erb +11 -0
- data/app/views/rails_trade_admin/payment_references/destroy.js.erb +1 -0
- data/app/views/rails_trade_admin/payment_references/edit.html.erb +6 -0
- data/app/views/rails_trade_admin/payment_references/index.html.erb +25 -0
- data/app/views/rails_trade_admin/payment_references/new.js.erb +8 -0
- data/app/views/rails_trade_admin/payment_references/show.html.erb +4 -0
- data/app/views/rails_trade_admin/payment_strategies/_form.html.erb +5 -0
- data/app/views/rails_trade_admin/payment_strategies/edit.html.erb +13 -0
- data/app/views/rails_trade_admin/payment_strategies/index.html.erb +37 -0
- data/app/views/rails_trade_admin/payment_strategies/new.html.erb +13 -0
- data/app/views/rails_trade_admin/payments/_form.html.erb +12 -0
- data/app/views/rails_trade_admin/payments/_item.html.erb +49 -0
- data/app/views/rails_trade_admin/payments/_search_form.html.erb +15 -0
- data/app/views/rails_trade_admin/payments/analyze.js.erb +12 -0
- data/app/views/rails_trade_admin/payments/dashboard.html.erb +4 -0
- data/app/views/rails_trade_admin/payments/edit.html.erb +15 -0
- data/app/views/rails_trade_admin/payments/index.html.erb +60 -0
- data/app/views/rails_trade_admin/payments/new.html.erb +17 -0
- data/app/views/rails_trade_admin/payments/show.html.erb +4 -0
- data/app/views/rails_trade_admin/promote_buyers/_form.html.erb +6 -0
- data/app/views/rails_trade_admin/promote_buyers/_promote_buyer.json.jbuilder +2 -0
- data/app/views/rails_trade_admin/promote_buyers/edit.html.erb +14 -0
- data/app/views/rails_trade_admin/promote_buyers/index.html.erb +42 -0
- data/app/views/rails_trade_admin/promote_buyers/index.json.jbuilder +1 -0
- data/app/views/rails_trade_admin/promote_buyers/new.html.erb +13 -0
- data/app/views/rails_trade_admin/promote_buyers/show.html.erb +0 -0
- data/app/views/rails_trade_admin/promote_buyers/show.json.jbuilder +1 -0
- data/app/views/rails_trade_admin/promote_charges/_edit.html.erb +13 -0
- data/app/views/rails_trade_admin/promote_charges/_form.html.erb +6 -0
- data/app/views/rails_trade_admin/promote_charges/_new.html.erb +13 -0
- data/app/views/rails_trade_admin/promote_charges/_search_form.html.erb +9 -0
- data/app/views/rails_trade_admin/promote_charges/edit.js.erb +8 -0
- data/app/views/rails_trade_admin/promote_charges/index.html.erb +49 -0
- data/app/views/rails_trade_admin/promote_charges/new.js.erb +8 -0
- data/app/views/rails_trade_admin/promote_goods/_form.html.erb +4 -0
- data/app/views/rails_trade_admin/promote_goods/_promote_good.json.jbuilder +2 -0
- data/app/views/rails_trade_admin/promote_goods/edit.html.erb +14 -0
- data/app/views/rails_trade_admin/promote_goods/index.html.erb +37 -0
- data/app/views/rails_trade_admin/promote_goods/index.json.jbuilder +1 -0
- data/app/views/rails_trade_admin/promote_goods/new.html.erb +13 -0
- data/app/views/rails_trade_admin/promote_goods/show.html.erb +0 -0
- data/app/views/rails_trade_admin/promote_goods/show.json.jbuilder +1 -0
- data/app/views/rails_trade_admin/promotes/_form.html.erb +9 -0
- data/app/views/rails_trade_admin/promotes/edit.html.erb +9 -0
- data/app/views/rails_trade_admin/promotes/index.html.erb +65 -0
- data/app/views/rails_trade_admin/promotes/new.html.erb +9 -0
- data/app/views/rails_trade_admin/promotes/show.html.erb +4 -0
- data/app/views/rails_trade_admin/providers/_form.html.erb +6 -0
- data/app/views/rails_trade_admin/providers/_product.html.erb +12 -0
- data/app/views/rails_trade_admin/providers/_side.html.erb +8 -0
- data/app/views/rails_trade_admin/providers/area.html.erb +1 -0
- data/app/views/rails_trade_admin/providers/channel.html.erb +46 -0
- data/app/views/rails_trade_admin/providers/edit.html.erb +16 -0
- data/app/views/rails_trade_admin/providers/index.html.erb +27 -0
- data/app/views/rails_trade_admin/providers/new.html.erb +21 -0
- data/app/views/rails_trade_admin/providers/posts.html.erb +41 -0
- data/app/views/rails_trade_admin/providers/products.html.erb +23 -0
- data/app/views/rails_trade_admin/providers/show.html.erb +60 -0
- data/app/views/rails_trade_admin/refunds/_form.html.erb +17 -0
- data/app/views/rails_trade_admin/refunds/_logs_table.html.erb +33 -0
- data/app/views/rails_trade_admin/refunds/_new.html.erb +18 -0
- data/app/views/rails_trade_admin/refunds/_search_form.html.erb +13 -0
- data/app/views/rails_trade_admin/refunds/edit.html.erb +6 -0
- data/app/views/rails_trade_admin/refunds/index.html.erb +57 -0
- data/app/views/rails_trade_admin/refunds/logs.js.erb +8 -0
- data/app/views/rails_trade_admin/refunds/new.html.erb +5 -0
- data/app/views/rails_trade_admin/refunds/new.js.erb +8 -0
- data/app/views/rails_trade_admin/refunds/show.html.erb +4 -0
- data/app/views/rails_trade_admin/serve_charges/_edit.html.erb +13 -0
- data/app/views/rails_trade_admin/serve_charges/_form.html.erb +10 -0
- data/app/views/rails_trade_admin/serve_charges/_new.html.erb +13 -0
- data/app/views/rails_trade_admin/serve_charges/_search_form.html.erb +10 -0
- data/app/views/rails_trade_admin/serve_charges/edit.js.erb +7 -0
- data/app/views/rails_trade_admin/serve_charges/index.html.erb +56 -0
- data/app/views/rails_trade_admin/serve_charges/new.js.erb +8 -0
- data/app/views/rails_trade_admin/serves/_form.html.erb +9 -0
- data/app/views/rails_trade_admin/serves/edit.html.erb +9 -0
- data/app/views/rails_trade_admin/serves/index.html.erb +80 -0
- data/app/views/rails_trade_admin/serves/new.html.erb +9 -0
- data/app/views/rails_trade_my/addresses/_edit.html.erb +31 -0
- data/app/views/rails_trade_my/addresses/_form.html.erb +23 -0
- data/app/views/rails_trade_my/addresses/_new.html.erb +11 -0
- data/app/views/rails_trade_my/addresses/create.js.erb +2 -0
- data/app/views/rails_trade_my/addresses/destroy.js.erb +1 -0
- data/app/views/rails_trade_my/addresses/edit.js.erb +39 -0
- data/app/views/rails_trade_my/addresses/index.html.erb +44 -0
- data/app/views/rails_trade_my/addresses/new.js.erb +39 -0
- data/app/views/rails_trade_my/addresses/show.html.erb +4 -0
- data/app/views/rails_trade_my/addresses/update.js.erb +2 -0
- data/app/views/rails_trade_my/base/_nav.html.erb +22 -0
- data/app/views/rails_trade_my/buyers/_form.html.erb +5 -0
- data/app/views/rails_trade_my/buyers/edit.html.erb +2 -0
- data/app/views/rails_trade_my/buyers/show.html.erb +21 -0
- data/app/views/rails_trade_my/cart_items/_additions.html.erb +22 -0
- data/app/views/rails_trade_my/cart_items/_single_price.html.erb +6 -0
- data/app/views/rails_trade_my/cart_items/_total_price.html.erb +8 -0
- data/app/views/rails_trade_my/cart_items/destroy.js.erb +1 -0
- data/app/views/rails_trade_my/cart_items/index.html.erb +69 -0
- data/app/views/rails_trade_my/cart_items/total.js.erb +11 -0
- data/app/views/rails_trade_my/cart_items/update.js.erb +8 -0
- data/app/views/rails_trade_my/my/index.html.erb +17 -0
- data/app/views/rails_trade_my/order_items/_form.html.erb +17 -0
- data/app/views/rails_trade_my/order_items/edit.html.erb +6 -0
- data/app/views/rails_trade_my/order_items/index.html.erb +25 -0
- data/app/views/rails_trade_my/order_items/new.html.erb +5 -0
- data/app/views/rails_trade_my/order_items/show.html.erb +8 -0
- data/app/views/rails_trade_my/orders/_date_form.html.erb +23 -0
- data/app/views/rails_trade_my/orders/_edit.html.erb +10 -0
- data/app/views/rails_trade_my/orders/_edit_payment_type.html.erb +13 -0
- data/app/views/rails_trade_my/orders/_form.html.erb +4 -0
- data/app/views/rails_trade_my/orders/destroy.js.erb +1 -0
- data/app/views/rails_trade_my/orders/edit.js.erb +4 -0
- data/app/views/rails_trade_my/orders/edit_payment_type.js.erb +6 -0
- data/app/views/rails_trade_my/orders/fail.html.erb +11 -0
- data/app/views/rails_trade_my/orders/index.html.erb +55 -0
- data/app/views/rails_trade_my/orders/index.json.jbuilder +9 -0
- data/app/views/rails_trade_my/orders/new.html.erb +41 -0
- data/app/views/rails_trade_my/orders/refresh.js.erb +7 -0
- data/app/views/rails_trade_my/orders/show.html.erb +103 -0
- data/app/views/rails_trade_my/orders/success.html.erb +12 -0
- data/app/views/rails_trade_my/orders/update.js.erb +3 -0
- data/app/views/rails_trade_my/orders/update_payment_type.js.erb +3 -0
- data/app/views/rails_trade_my/orders/wxpay_pay.js.erb +16 -0
- data/app/views/rails_trade_my/orders/wxpay_pay_err.js.erb +5 -0
- data/app/views/rails_trade_my/payment_methods/_edit.html.erb +13 -0
- data/app/views/rails_trade_my/payment_methods/_form.html.erb +5 -0
- data/app/views/rails_trade_my/payment_methods/_index.html.erb +25 -0
- data/app/views/rails_trade_my/payment_methods/_item.html.erb +10 -0
- data/app/views/rails_trade_my/payment_methods/_new.html.erb +13 -0
- data/app/views/rails_trade_my/payment_methods/create.js.erb +3 -0
- data/app/views/rails_trade_my/payment_methods/destroy.js.erb +1 -0
- data/app/views/rails_trade_my/payment_methods/edit.js.erb +8 -0
- data/app/views/rails_trade_my/payment_methods/index.html.erb +1 -0
- data/app/views/rails_trade_my/payment_methods/index.js.erb +1 -0
- data/app/views/rails_trade_my/payment_methods/new.js.erb +8 -0
- data/app/views/rails_trade_my/payment_methods/show.html.erb +4 -0
- data/app/views/rails_trade_my/payment_methods/update.js.erb +2 -0
- data/app/views/rails_trade_my/providers/_form.html.erb +5 -0
- data/app/views/rails_trade_my/providers/_provider.html.erb +20 -0
- data/app/views/rails_trade_my/providers/edit.html.erb +2 -0
- data/app/views/rails_trade_my/providers/index.html.erb +12 -0
- data/app/views/rails_trade_my/providers/new.html.erb +10 -0
- data/app/views/rails_trade_my/providers/show.html.erb +13 -0
- data/app/views/rails_trade_my/users/_form.html.erb +17 -0
- data/app/views/rails_trade_my/users/edit.html.erb +44 -0
- data/app/views/rails_trade_my/users/show.html.erb +18 -0
- data/config/locales/en.yml +85 -0
- data/config/locales/zh.yml +75 -0
- data/config/routes.rb +118 -0
- data/db/migrate/20150514135720_create_providers.rb +59 -0
- data/db/migrate/20170601014520_create_payments.rb +52 -0
- data/db/migrate/20170602061859_create_payment_references.rb +12 -0
- data/db/migrate/20170702234123_create_orders.rb +56 -0
- data/db/migrate/20170714080032_create_payment_strategies.rb +77 -0
- data/db/migrate/20171115063702_create_promote_buyers.rb +31 -0
- data/db/schema.rb +94 -0
- data/lib/rails_trade.rb +22 -0
- data/lib/rails_trade/config.rb +12 -0
- data/lib/rails_trade/engine.rb +30 -0
- data/lib/rails_trade/version.rb +3 -0
- data/lib/tasks/the_trade_tasks.rake +4 -0
- metadata +491 -0
@@ -0,0 +1,88 @@
|
|
1
|
+
class OrderItem < ApplicationRecord
|
2
|
+
belongs_to :order, autosave: true, inverse_of: :order_items
|
3
|
+
belongs_to :cart_item, optional: true, autosave: true
|
4
|
+
belongs_to :good, polymorphic: true, optional: true
|
5
|
+
belongs_to :provider, optional: true
|
6
|
+
has_many :order_promotes, autosave: true
|
7
|
+
has_many :order_serves, autosave: true
|
8
|
+
has_many :serves, through: :order_serves
|
9
|
+
|
10
|
+
composed_of :promote,
|
11
|
+
class_name: 'PromoteFee',
|
12
|
+
mapping: [['good_type', 'good_type'], ['good_id', 'good_id'], ['quantity', 'number']]
|
13
|
+
composed_of :serve,
|
14
|
+
class_name: 'ServeFee',
|
15
|
+
mapping: [['good_type', 'good_type'], ['good_id', 'good_id'], ['quantity', 'number']]
|
16
|
+
|
17
|
+
after_initialize if: :new_record? do |oi|
|
18
|
+
if cart_item
|
19
|
+
self.good_type = cart_item.good_type
|
20
|
+
self.good_id = cart_item.good_id
|
21
|
+
self.number = cart_item.quantity
|
22
|
+
self.pure_price = cart_item.pure_price
|
23
|
+
self.advance_payment = self.good.advance_payment if self.advance_payment.to_f.zero?
|
24
|
+
#self.provider = cart_item.good.provider
|
25
|
+
|
26
|
+
cart_item.serve_charges.each do |serve_charge|
|
27
|
+
op = self.order_serves.build(serve_charge_id: serve_charge.id, serve_id: serve_charge.serve_id, amount: serve_charge.subtotal)
|
28
|
+
op.order = self.order
|
29
|
+
end
|
30
|
+
cart_item.promote.charges.each do |promote_charge|
|
31
|
+
op = self.order_promotes.build(promote_charge_id: promote_charge.id, promote_id: promote_charge.promote_id, amount: promote_charge.subtotal)
|
32
|
+
op.order = self.order
|
33
|
+
end
|
34
|
+
compute_sum
|
35
|
+
|
36
|
+
unless self.amount == cart_item.final_price
|
37
|
+
puts 'amount is wrong'
|
38
|
+
end
|
39
|
+
|
40
|
+
cart_item.status = 'ordered'
|
41
|
+
end
|
42
|
+
end
|
43
|
+
after_update_commit :sync_amount, if: -> { saved_change_to_amount? }
|
44
|
+
|
45
|
+
def sync_amount
|
46
|
+
order.compute_sum
|
47
|
+
order.save
|
48
|
+
end
|
49
|
+
|
50
|
+
def compute_sum
|
51
|
+
self.serve_sum = self.order_serves.sum { |os| os.amount }
|
52
|
+
self.promote_sum = self.order_promotes.sum { |op| op.amount }
|
53
|
+
self.amount = self.pure_price + self.serve_sum + self.promote_sum # 校验是否等于cart_item.final_price
|
54
|
+
end
|
55
|
+
|
56
|
+
def confirm_ordered!
|
57
|
+
self.good.order_done
|
58
|
+
end
|
59
|
+
|
60
|
+
def confirm_paid!
|
61
|
+
|
62
|
+
end
|
63
|
+
|
64
|
+
def confirm_part_paid!
|
65
|
+
|
66
|
+
end
|
67
|
+
|
68
|
+
def confirm_refund!
|
69
|
+
|
70
|
+
end
|
71
|
+
|
72
|
+
end unless RailsTrade.config.disabled_models.include?('OrderItem')
|
73
|
+
|
74
|
+
# :cart_item_id, :integer
|
75
|
+
# :good_type, :string
|
76
|
+
# :good_id, :integer
|
77
|
+
# :quantity, :float
|
78
|
+
# :unit, :string
|
79
|
+
# :number, :integer, limit: 4, default: 1
|
80
|
+
# :total_price, :decimal, limit: 24
|
81
|
+
# :order_at :datetime
|
82
|
+
# :payed_at :datetime
|
83
|
+
# :comment, :string
|
84
|
+
# :deliver_on, :date
|
85
|
+
# #advance_payment, :decimal, precision: 10, scale: 2
|
86
|
+
|
87
|
+
|
88
|
+
|
@@ -0,0 +1,23 @@
|
|
1
|
+
class OrderPromote < ApplicationRecord
|
2
|
+
belongs_to :order, inverse_of: :order_promotes
|
3
|
+
belongs_to :order_item, optional: true
|
4
|
+
belongs_to :promote
|
5
|
+
belongs_to :promote_charge, optional: true
|
6
|
+
|
7
|
+
after_update_commit :sync_amount, if: -> { saved_change_to_amount? }
|
8
|
+
|
9
|
+
def sync_amount
|
10
|
+
if self.order_item_id.nil?
|
11
|
+
order.compute_sum
|
12
|
+
order.save
|
13
|
+
else
|
14
|
+
order_item.compute_sum
|
15
|
+
order_item.save
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
end unless RailsTrade.config.disabled_models.include?('OrderPromtote')
|
20
|
+
|
21
|
+
# :order_id, :integer
|
22
|
+
# :order_item_id :integer
|
23
|
+
|
@@ -0,0 +1,23 @@
|
|
1
|
+
class OrderServe < ApplicationRecord
|
2
|
+
belongs_to :order, inverse_of: :order_serves
|
3
|
+
belongs_to :order_item, optional: true
|
4
|
+
belongs_to :serve_charge, optional: true
|
5
|
+
belongs_to :serve
|
6
|
+
|
7
|
+
after_update_commit :sync_amount, if: -> { saved_change_to_amount? }
|
8
|
+
|
9
|
+
def sync_amount
|
10
|
+
if self.order_item_id.nil?
|
11
|
+
order.compute_sum
|
12
|
+
order.save
|
13
|
+
else
|
14
|
+
order_item.compute_sum
|
15
|
+
order_item.save
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
end unless RailsTrade.config.disabled_models.include?('OrderServe')
|
20
|
+
|
21
|
+
# :order_id, :integer
|
22
|
+
# :order_item_id :integer
|
23
|
+
|
@@ -0,0 +1,135 @@
|
|
1
|
+
class Payment < ApplicationRecord
|
2
|
+
include Auditable
|
3
|
+
|
4
|
+
attribute :currency, :string, default: 'USD'
|
5
|
+
|
6
|
+
belongs_to :payment_method, optional: true
|
7
|
+
has_many :payment_orders, dependent: :destroy, inverse_of: :payment
|
8
|
+
has_many :orders, through: :payment_orders, inverse_of: :payments
|
9
|
+
|
10
|
+
default_scope -> { order(created_at: :desc) }
|
11
|
+
|
12
|
+
validates :total_amount, numericality: { equal_to: -> (o) { o.income_amount + o.fee_amount } }, if: -> { income_amount.present? && fee_amount.present? && total_amount.present? }
|
13
|
+
validates :adjust_amount, numericality: { less_than: 1, greater_than: -1 }, allow_blank: true
|
14
|
+
validates :payment_uuid, uniqueness: true
|
15
|
+
|
16
|
+
before_save :compute_amount
|
17
|
+
after_create :analyze_payment_method
|
18
|
+
|
19
|
+
#has_one_attached :proof
|
20
|
+
|
21
|
+
after_initialize if: :new_record? do |o|
|
22
|
+
self.payment_uuid ||= UidHelper.nsec_uuid('PAY')
|
23
|
+
end
|
24
|
+
|
25
|
+
enum state: [
|
26
|
+
:init,
|
27
|
+
:part_checked,
|
28
|
+
:all_checked,
|
29
|
+
:abusive_checked
|
30
|
+
]
|
31
|
+
|
32
|
+
def analyze_payment_method
|
33
|
+
if self.buyer_name.present? || self.buyer_identifier.present?
|
34
|
+
pm = PaymentMethod.find_or_initialize_by(account_name: self.buyer_name.to_s, account_num: self.buyer_identifier.to_s)
|
35
|
+
pm.bank = self.buyer_bank
|
36
|
+
self.payment_method = pm
|
37
|
+
|
38
|
+
pm.save
|
39
|
+
self.save
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def unchecked_amount
|
44
|
+
total_amount.to_d - pending_checked_amount.to_d
|
45
|
+
end
|
46
|
+
|
47
|
+
def pending_checked_amount
|
48
|
+
PaymentOrder.where(payment_id: self.id).sum(:check_amount)
|
49
|
+
end
|
50
|
+
|
51
|
+
def compute_amount
|
52
|
+
if total_amount.blank? && fee_amount.present? && income_amount.present?
|
53
|
+
self.total_amount = self.fee_amount + self.income_amount
|
54
|
+
end
|
55
|
+
|
56
|
+
if income_amount.blank? && total_amount.present? && fee_amount.present?
|
57
|
+
self.income_amount = self.total_amount - self.fee_amount
|
58
|
+
end
|
59
|
+
|
60
|
+
if fee_amount.blank? && total_amount.present? && income_amount.present?
|
61
|
+
self.fee_amount = self.total_amount - self.income_amount
|
62
|
+
end
|
63
|
+
self.check_state
|
64
|
+
end
|
65
|
+
|
66
|
+
def pending_orders
|
67
|
+
if self.payment_method
|
68
|
+
buyer_ids = self.payment_method.payment_references.pluck(:buyer_id)
|
69
|
+
Order.where.not(id: self.payment_orders.pluck(:order_id)).where(buyer_id: buyer_ids, payment_status: ['unpaid', 'part_paid'], state: 'active')
|
70
|
+
else
|
71
|
+
[]
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def analyze_adjust_amount
|
76
|
+
self.adjust_amount = init_adjust_amount
|
77
|
+
self.state = 'all_checked'
|
78
|
+
self.save
|
79
|
+
end
|
80
|
+
|
81
|
+
def init_adjust_amount
|
82
|
+
self.checked_amount.to_d - self.total_amount.to_d
|
83
|
+
end
|
84
|
+
|
85
|
+
def check_order(order_id)
|
86
|
+
order = Order.find order_id
|
87
|
+
payment_order = self.payment_orders.build(order_id: order.id)
|
88
|
+
payment_order.check_amount = order.unreceived_amount
|
89
|
+
payment_order.save
|
90
|
+
|
91
|
+
payment_order
|
92
|
+
end
|
93
|
+
|
94
|
+
def check_state
|
95
|
+
if checked_amount.to_d >= total_amount
|
96
|
+
self.state = 'all_checked'
|
97
|
+
self.adjust_amount = self.checked_amount.to_d - self.total_amount
|
98
|
+
elsif self.checked_amount.to_d > 0 && self.checked_amount.to_d < self.total_amount
|
99
|
+
self.state = 'part_checked'
|
100
|
+
elsif self.checked_amount.to_d == 0
|
101
|
+
self.state = 'init'
|
102
|
+
else
|
103
|
+
self.state = 'abusive_checked'
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
def check_state!
|
108
|
+
self.check_state
|
109
|
+
self.save!
|
110
|
+
end
|
111
|
+
|
112
|
+
def self.total_amount_step
|
113
|
+
0.1.to_d.power(Payment.columns_hash['total_amount'].scale)
|
114
|
+
end
|
115
|
+
|
116
|
+
end unless RailsTrade.config.disabled_models.include?('Payment')
|
117
|
+
|
118
|
+
# :id, :integer, limit: 4, null: false
|
119
|
+
# :type, :string, limit: 255
|
120
|
+
# :total_amount, :decimal, precision: 10, scale: 2
|
121
|
+
# :order_amount, :decimal, precision: 10, scale: 2
|
122
|
+
# :fee_amount, :decimal, precision: 10, scale: 2
|
123
|
+
# :payment_uuid, :string, limit: 255
|
124
|
+
# :notify_type, :string, limit: 255
|
125
|
+
# :notified_at, :datetime, precision: 0
|
126
|
+
# :pay_status, :string, limit: 255
|
127
|
+
# :buyer_email, :string, limit: 255
|
128
|
+
# :sign, :string, limit: 255
|
129
|
+
# :seller_identifier, :string, limit: 255
|
130
|
+
# :buyer_identifier, :string, limit: 255
|
131
|
+
# :user_id, :integer, limit: 4
|
132
|
+
# :currency, :string, limit: 255
|
133
|
+
# :state, :integer, limit: 4, default: 0
|
134
|
+
# :created_at, :datetime, precision: 0, null: false
|
135
|
+
# :updated_at, :datetime, precision: 0, null: false
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module TheAlipay
|
2
|
+
extend ActiveSupport::Concern
|
3
|
+
|
4
|
+
included do
|
5
|
+
end
|
6
|
+
|
7
|
+
def alipay_prepay
|
8
|
+
self.update payment_type: 'alipay'
|
9
|
+
Alipay2::Service.trade_app_pay_params(subject: self.subject, out_trade_no: self.uuid, total_amount: self.amount.to_s)
|
10
|
+
end
|
11
|
+
|
12
|
+
def alipay_prepay_url
|
13
|
+
self.update payment_type: 'alipay'
|
14
|
+
Alipay2::Service.trade_page_pay subject: self.subject, out_trade_no: self.uuid, total_amount: self.amount.to_s
|
15
|
+
end
|
16
|
+
|
17
|
+
# 3 step: check result
|
18
|
+
def alipay_result
|
19
|
+
result = Alipay2::Service.trade_query out_trade_no: self.uuid
|
20
|
+
result = JSON.parse(result)
|
21
|
+
result = result['alipay_trade_query_response']
|
22
|
+
alipay_record(result)
|
23
|
+
end
|
24
|
+
|
25
|
+
def alipay_record(result)
|
26
|
+
if result['trade_status'] == 'TRADE_SUCCESS'
|
27
|
+
alipay = AlipayPayment.find_by(payment_uuid: result['trade_no'])
|
28
|
+
return alipay if alipay
|
29
|
+
|
30
|
+
alipay = AlipayPayment.new
|
31
|
+
alipay.payment_uuid = result['trade_no']
|
32
|
+
alipay.buyer_identifier = result['buyer_user_id']
|
33
|
+
alipay.total_amount = result['total_amount']
|
34
|
+
alipay.income_amount = result['receipt_amount']
|
35
|
+
alipay.notified_at = result['send_pay_date']
|
36
|
+
|
37
|
+
payment_order = alipay.payment_orders.build(order_id: self.id, check_amount: alipay.total_amount)
|
38
|
+
|
39
|
+
Payment.transaction do
|
40
|
+
payment_order.confirm!
|
41
|
+
alipay.save!
|
42
|
+
end
|
43
|
+
alipay
|
44
|
+
else
|
45
|
+
errors.add :uuid, result['msg']
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
@@ -0,0 +1,103 @@
|
|
1
|
+
module ThePaypal
|
2
|
+
extend ActiveSupport::Concern
|
3
|
+
|
4
|
+
included do
|
5
|
+
delegate :url_helpers, to: 'Rails.application.routes'
|
6
|
+
end
|
7
|
+
|
8
|
+
def paypal_prepay
|
9
|
+
paypal_payment = PayPal::SDK::REST::DataTypes::Payment.new(paypal_params)
|
10
|
+
|
11
|
+
result = paypal_payment.create
|
12
|
+
if result
|
13
|
+
self.update(payment_id: paypal_payment.id)
|
14
|
+
else
|
15
|
+
self.errors.add :payment_id, paypal_payment.error.inspect
|
16
|
+
end
|
17
|
+
paypal_payment.links.find{ |v| v.rel == 'approval_url' }.href
|
18
|
+
end
|
19
|
+
|
20
|
+
def paypal_execute(params)
|
21
|
+
return unless self.payment_id
|
22
|
+
paypal_payment = PayPal::SDK::REST::DataTypes::Payment.find(self.payment_id)
|
23
|
+
paypal_payment.execute(payer_id: params[:PayerID])
|
24
|
+
|
25
|
+
paypal_record(paypal_payment)
|
26
|
+
end
|
27
|
+
|
28
|
+
def paypal_result
|
29
|
+
return unless self.payment_id
|
30
|
+
self.paypal_payment ||= PayPal::SDK::REST::DataTypes::Payment.find(self.payment_id)
|
31
|
+
|
32
|
+
paypal_record(paypal_payment)
|
33
|
+
end
|
34
|
+
|
35
|
+
def paypal_record(record)
|
36
|
+
trans = record.transactions[0]
|
37
|
+
|
38
|
+
if record.state == 'approved'
|
39
|
+
paypal = PaypalPayment.find_by(payment_uuid: trans.related_resources[0].sale.id)
|
40
|
+
return paypal if paypal
|
41
|
+
|
42
|
+
paypal = PaypalPayment.new
|
43
|
+
paypal.payment_uuid = trans.related_resources[0].sale.id
|
44
|
+
paypal.total_amount = trans.amount.total
|
45
|
+
|
46
|
+
payment_order = paypal.payment_orders.build(order_id: self.id, check_amount: paypal.total_amount)
|
47
|
+
|
48
|
+
Payment.transaction do
|
49
|
+
payment_order.confirm!
|
50
|
+
paypal.save!
|
51
|
+
end
|
52
|
+
paypal
|
53
|
+
else
|
54
|
+
errors.add :uuid, record.error.inspect
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def paypal_params
|
59
|
+
{
|
60
|
+
intent: 'sale',
|
61
|
+
payer: {
|
62
|
+
payment_method: 'paypal'
|
63
|
+
},
|
64
|
+
redirect_urls: {
|
65
|
+
return_url: url_helpers.paypal_execute_my_order_url(self.id),
|
66
|
+
cancel_url: url_helpers.cancel_my_order_url(self.id)
|
67
|
+
},
|
68
|
+
transactions: {
|
69
|
+
item_list: {
|
70
|
+
items: paypal_items_params
|
71
|
+
},
|
72
|
+
amount: {
|
73
|
+
total: self.unreceived_amount,
|
74
|
+
currency: self.currency.upcase
|
75
|
+
},
|
76
|
+
description: ''
|
77
|
+
}
|
78
|
+
}
|
79
|
+
end
|
80
|
+
|
81
|
+
def paypal_items_params
|
82
|
+
items = order_items.map do |item|
|
83
|
+
{
|
84
|
+
name: item.good.name,
|
85
|
+
sku: item.good.sku,
|
86
|
+
price: item.good.price.to_money.exchange_to(self.currency).to_s,
|
87
|
+
currency: self.currency.upcase,
|
88
|
+
quantity: item.number
|
89
|
+
}
|
90
|
+
end
|
91
|
+
serves = order_serves.map do |item|
|
92
|
+
{
|
93
|
+
name: item.serve.name,
|
94
|
+
sku: item.serve.id,
|
95
|
+
price: item.price.to_money.exchange_to(self.currency).to_s,
|
96
|
+
currency: self.currency.upcase,
|
97
|
+
quantity: 1
|
98
|
+
}
|
99
|
+
end
|
100
|
+
items + serves
|
101
|
+
end
|
102
|
+
|
103
|
+
end
|