Square Inc. has agreed an all-stock deal worth around $29 billion to acquire Australia’s Afterpay Ltd., an installment-payment company that positions its service as a cheaper and more responsible alternative to a credit card.