createOrder method

Future<Order> createOrder(
  1. OrderRequest request, {
  2. String? payPalRequestId,
  3. String? payPalPartnerAttributionId,
  4. String? payPalClientMetadataId,
  5. Prefer? prefer,
})

Creates an order

Parameter request: The create order request object

Parameter payPalRequestId: The server stores keys for 6 hours. The API callers can request the times to up to 72 hours by speaking to their Account Manager.

Parameter payPalPartnerAttributionId:

Parameter payPalClientMetadataId:

Parameter prefer: 'minimal', The server returns a minimal response to optimize communication between the API caller and the server. A minimal response includes the id, status and HATEOAS links. 'representation', The server returns a complete resource representation, including the current state of the resource.

Implementation

Future<Order> createOrder(
  OrderRequest request, {
  String? payPalRequestId,
  String? payPalPartnerAttributionId,
  String? payPalClientMetadataId,
  Prefer? prefer,
}) async {
  var uri = _payPalHttpClient.getUrl('/v2/checkout/orders');

  var headers = <String, String>{};

  if (payPalRequestId != null) {
    headers['PayPal-Request-Id'] = payPalRequestId;
  }

  if (payPalPartnerAttributionId != null) {
    headers['PayPal-Partner-Attribution-Id'] = payPalPartnerAttributionId;
  }

  if (payPalClientMetadataId != null) {
    headers['PayPal-Client-Metadata-Id'] = payPalClientMetadataId;
  }

  if (prefer != null) {
    headers['Prefer'] = preferTypeEnumMap[prefer]!;
  }

  var body = jsonEncode(request.toJson());

  var response =
      await _payPalHttpClient.post(uri, headers: headers, body: body);
  return Order.fromJson(jsonDecode(response.body));
}