Class: Docdata::Order::CreateRequest

Inherits:
Request
  • Object
show all
Defined in:
lib/docdata/order/request.rb

Overview

Create an Order in the Docdata system.

Instance Attribute Summary

Attributes inherited from Request

#options

Instance Method Summary collapse

Methods inherited from Request

#initialize, #to_s

Constructor Details

This class inherits a constructor from Docdata::Order::Request

Instance Method Details

#build_request(builder) ⇒ Object



113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
# File 'lib/docdata/order/request.rb', line 113

def build_request(builder)
  # Unique merchant reference to this order.
  builder.merchantOrderReference(order_reference)

  # Preferences to use for this payment.
  builder.paymentPreferences do |preferences|
    # The profile that is used to select the payment methods that can be used to pay this order.
    preferences.profile(profile)
    preferences.numberOfDaysToPay(14)
  end

  # Information concerning the shopper who placed the order.
  builder.shopper(id: shopper_id) do |shopper|
    # Shopper's full name.
    shopper.name do |name|
      # The first given name.
      name.first(shopper_first_name)
      # Any subsequent given name or names. May also be used as middle initial.
      name.middle(shopper_infix) if shopper_infix
      # The family or inherited name(s).
      name.last(shopper_last_name)
    end

    # Shopper's e-mail address.
    shopper.email(shopper_email)
    # Shopper's preferred language. Language code according to ISO 639.
    shopper.language(code: shopper_language)
    # Shopper's gender.
    shopper.gender(shopper_gender)
    # Ip address of the shopper. Will be used in the future for riskchecks. Can be ipv4 or ipv6.
    shopper.ipAddress(shopper_ip_address) if shopper_ip_address
  end

  # Total order gross amount. The amount in the minor unit for the given currency.
  # (E.g. for EUR in cents)
  builder.totalGrossAmount(amount, currency: currency)

  # Name and address to use for billing.
  builder.billTo do |bill|
    bill.name do |name|
      # The first given name.
      name.first(shopper_first_name)
      # Any subsequent given name or names. May also be used as middle initial.
      name.middle(shopper_infix) if shopper_infix
      # The family or inherited name(s).
      name.last(shopper_last_name)
    end
    # Address of the destination.
    bill.address do |address|
      # Address lines must be filled as specific as possible using the house number
      # and optionally the house number addition field.
      address.street(address_street)
      # The house number.
      address.houseNumber(address_house_number)
      address.postalCode(address_postal_code)
      address.city(address_city)
      # Country code according to ISO 3166.
      address.country(code: address_country)
    end
  end

  # The description of the order.
  builder.description(description)

  # The description that is used by payment providers on shopper statements.
  builder.receiptText(receipt_text)

  # The merchant_reference is used for recurring payments.
  if initial
    builder.paymentRequest do |payment_request|
      payment_request.initialPaymentReference do |payment_reference|
        payment_reference.merchantReference(merchant_reference)
      end
    end
  end
end