JPMorgan Chase has agreed to take over the loans underpinning Apple’s credit card portfolio from rival Goldman Sachs, extricating it from one of the last businesses related to an ill-fated foray into retail banking.