Class: Sap::Payment

Inherits:
SapAnywhereInterface show all
Defined in:
lib/resource/sap/payment.rb

Instance Method Summary collapse

Methods inherited from SapAnywhereInterface

#check_access_token, #check_function_and_shop, #convert_payment_type, #convert_price_unit, #delete, #get, #get_access_token, #get_access_token_url, #handle_response, #patch, #post

Constructor Details

#initialize(source) ⇒ Payment

Note:

对象初始化方法(初始化来源)

对象初始化方法(初始化来源)

Parameters:

  • source (string)


9
10
11
# File 'lib/resource/sap/payment.rb', line 9

def initialize(source)
  @source = source
end

Instance Method Details

#convert_to_sap_payment(params) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/resource/sap/payment.rb', line 64

def convert_to_sap_payment(params)

  sap_payment = yhash
  # 汇率
  sap_payment.exchangeRate = 1

  # 顾客信息
  sap_payment.customer = yhash
  sap_payment.customer.id = params[:customer_id] #暂时还无法改,需要把客户信息也同步到sap

  # 联系人信息
  # sap_payment.contactPerson = yhash
  # sap_payment.contactPerson.id = ''

  # 参考编号
  sap_payment.referenceNumber = nil

  # 订单的时间
  sap_payment.postingTime = params[:order].try(:created_at)

  # 付款评价
  sap_payment.remark = nil

  # 货币单位
  sap_payment.currency = yhash
  # sap_payment.currency.code = params[:order][:currency][:code]
  sap_payment.currency.code = convert_price_unit(params[:order])
  # sap_payment.currency.isoCode = params[:order][:currency][:isoCode]

  # 收付款行
  sap_payment.paymentLines = [
      {
          transactionDocument: {
            id: params[:invoice][:id],
            type: 'Invoice'   # 必须是Invoice, CreditMemo, Prepayment
          },
          appliedAmount: {
            amount: params[:invoice][:grossTotal][:amount] # 订单总金额
          }
      }
  ]

  # 付款方式行
  sap_payment.paymentMethodLines = []
  cash_payment_method_line = yhash
  cash_payment_method_line.paymentMethod = yhash
  cash_payment_method_line.paymentMethod.id = 1
  cash_payment_method_line.paymentMethod.name = '现金'
  cash_payment_method_line.paymentMethod.type = 'CASH'
  cash_payment_method_line.amount = yhash
  cash_payment_method_line.amount.amount = params[:order][:pay_cash_total_price]
  sap_payment.paymentMethodLines << cash_payment_method_line
  # 需要在sap平台上添加积分付款方式,不然这里是按照paymentMethod的id来取付款方式的
  if !params[:order][:point_pay_total_price].zero?
    point_payment_method_line = yhash
    point_payment_method_line.paymentMethod = yhash
    point_payment_method_line.paymentMethod.id = 2
    point_payment_method_line.paymentMethod.name = '积分'
    point_payment_method_line.paymentMethod.type = 'OTHERS'
    point_payment_method_line.amount = yhash
    point_payment_method_line.amount.amount = params[:order][:point_pay_total_price]
    sap_payment.paymentMethodLines << point_payment_method_line
  end

  sap_payment

end

#find(id) ⇒ Object

Note:

通过接口获得单个数据

通过接口获得单个数据

Parameters:

  • id (Integer)

    数据id



24
25
26
# File 'lib/resource/sap/payment.rb', line 24

def find(id)
  get(query(id))
end

#listObject

Note:

通过接口获得一堆数据

通过接口获得一堆数据

Parameters:

  • source (string)

    来源

  • request_name (string)

    请求资源名



17
18
19
# File 'lib/resource/sap/payment.rb', line 17

def list
  get(query)
end

#query(params = {}, id = {}) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/resource/sap/payment.rb', line 40

def  query(params = {}, id = {})
  # Rails.logger.info params[:user_id]
  request_names = if params.class == Fixnum
                    "#{request_name}/#{params}?expand=*&"
                  elsif id.class == Fixnum
                    "#{request_name}/#{id}?expand=*&"
                  else
                    "#{request_name}?expand=*&"
                  end
  post_params = {
      source: @source,
      request_name: request_names
  }
  # Rails.logger.info "params是#{params}"
  # Rails.logger.info "id是#{id}"
  if params.class != Fixnum && params.present?
    post_params.merge!(payment: convert_to_sap_payment(params))
    # Rails.logger.info "post_params#{post_params}"
  end
  post_params.merge(id: id) if id.class == Fixnum
  # Rails.logger.info "当前参数#{post_params}"
  post_params
end

#request_nameObject

Note:

获取请求路径的请求名

获取请求路径的请求名



36
37
38
# File 'lib/resource/sap/payment.rb', line 36

def request_name
  'Payments'
end

#upload(payment_order) ⇒ Object

将收付款单数据从云店家上传到sap

Parameters:

  • payment_order (Order)

    订单



30
31
32
# File 'lib/resource/sap/payment.rb', line 30

def upload(payment_order)
  payment_id = post(query(payment_order))
end