iOS Mobile SDK: Notify Purchase Event

The “Notify Purchase Event” is used to describe a purchase made by the customer. It notifies, via Mobile SDK, when a user makes a purchase using the sendPurchase method.

 

How to use it

The purchase information notification uses the method Connectif.sendPurchase(purchase: Purchase), where we will add the purchase property with all the purchase information.

Notify the completed purchase

This object represents the Shopping Cart model that includes the following properties:

Name Required Type Description
purchaseId Yes String Unique identifier of the purchase.
cartId No String Unique identifier of the cart from which this purchase originated.
totalQuantity Yes Int Total quantity of products in the purchase (including duplicates). For example: if a cart has 3 units of one product and 7 units of another, totalQuantity will be 10.
totalPrice Yes Decimal Total amount of the purchase.
purchaseDate No Date Date of the purchase.
paymentMethod No String The payment method.
products Yes Product Basket Item Items contained in the purchase, along with their quantity and price.

This type of event automatically collects the following information:

  • Operating system: Android or iOS.
  • App version.
  • Operating system version.
  • Connectif SDK version.

 

Example

The notification will look like this:

let productBasketItem = ProductBasketItem(
    productDetailUrl: "https://example.com/product/12345",
    productId: "59a31949a1a562d4979fbca2",
    name: "Example Product",
    unitPrice: Decimal(51.88),
    description: "This is an example product",
    imageUrl: "https://example.com/product/images/12345.jpg",
    categories: ["Electronics", "Gadgets"],
    tags: ["Trending", "New Arrival"],
    brand: "ExampleBrand",
    reviewCount: 150,
    rating: Decimal(4.5),
    ratingCount: 124,
    thumbnailUrl: "https://example.com/product/thumbnails/12345.jpg",
    unitPriceOriginal: Decimal(120.00), 
    unitPriceWithoutVAT: Decimal(80.00), 
    discountedAmount: Decimal(20.00), 
    discountedPercentage: Decimal(16.67),
    publishedAt: Date(),
    customField1: "Special Edition",
    customField2: "Limited Stock",
    customField3: "Online Only",
    price: Decimal(51.88),
    quantity: 1
)

let purchase = Purchase(
    products: [productBasketItem],
    totalQuantity: 1,
    totalPrice: Decimal(51.88),
    cartId: "cart-0098caf9-42f4-44e9-afdd-45eafe892293",
    paymentMethod = "Credit Card",
    purchaseDate = Date(),
    purchaseId = "purchase-e3418b5a-8709-4593-a7c8-d8a7f12df737"
)

Connectif.sendPurchase(purchase)

 

Callbacks (Opcional)

Si queremos tener feedback de posibles errores al enviar eventos, podremos añadir un EventCallbacks cuando usemos nuestro método.

EventCallbacks(
    onSuccess: {
        // Manejo en caso de éxito
    },
    onError: { error in
        // Manejo en caso de error
    })

 

Congratulations!
You've reached the end of the lesson.

  

Do you still have unresolved questions?
Remember that our Connectif specialists are available to assist you. To contact them, simply open a support ticket by clicking on the blue "Help" button in your dashboard.


Keep Learning!

To fully unlock the potential of your Connectif account, we recommend continuing with the following articles:

 
Was this article helpful?
0 out of 0 found this helpful