createProduct method

Future<Product> createProduct(
  1. ProductRequest request, {
  2. String? payPalRequestId,
  3. Prefer? prefer,
})

Creates a product.

Parameter request: The create product 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 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<Product> createProduct(
  ProductRequest request, {
  String? payPalRequestId,
  Prefer? prefer,
}) async {
  var uri = _payPalHttpClient.getUrl('/v1/catalogs/products');

  var headers = <String, String>{};

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

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

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

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