Affirm Holdings posted an unexpected second-quarter profit as the provider of buy now, pay later loans saw a jump in its customer base.