After the harvest is done, farmers make quality tests (moisture, purity).
When a farmer has a buyer, the farmer may send a sample to the buyer for quality check, or what is more widespread may make laboratory test in an independent organization.
3rd party inspection service commonly used for export sales (the expenses will be paid by buyer).
When farmers harvest, they bring the product to the organization and do the quality test. For international buyers, farmers go to a third-party inspector/laboratory to prove the quality. If the farmers pay it, then they include it in the payment to be paid by the buyer.