$credentials = new Credentials();
$credentials->setAuthToken($authToken);
$credentials->setPublishableKey($publishableKey);
$credentials->setProcessorUserId($processorUserId);
$gateway = new Gateway();
$gateway->setCredentials($credentials);
$merchant->setGateway($gateway);
if ($_POST) {
    $m = $_POST['merchant'];
    $a = $_POST['address'];
    try {
        // Foreign Reference
        $merchant->setExternalId($m['externalId']);
        // Profile
        $merchant->setName($m['name']);
        $merchant->setEmail($m['email']);
        $merchant->setSupportEmail($m['supportEmail']);
        $domainCollection = new ArrayCollection($m['domains']);
        $merchant->setDomains($domainCollection);
        // Address
        $address = $merchant->getAddress();
        $address->setStreetAddressLine1($a['streetAddressLine1']);
        $address->setLocality($a['locality']);
        $address->setRegion($a['region']);
        $address->setPostalCode($a['postalCode']);
        $address->setCountry($a['country']);
        $processor->createMerchant($merchant);
        $processor->createPaymentProcessor($merchant);
        $success = sprintf('Twitter Merchant with ID %s attached to Payment Processor', $merchant->getId());
    } catch (\Exception $e) {
        $error = sprintf('%s: %s', get_class($e), $e->getMessage());