override def write()

in membership-common/src/main/scala/com/gu/zuora/soap/writers/Command.scala [210:275]


    override def write(command: Subscribe): Writer[Map[String, String], Elem] = {

      val now = DateTime.now
      val soldToContactNode = command.soldToContact.fold[NodeSeq](NodeSeq.Empty)(soldToContact => XmlWriter.write(soldToContact).value)
      val ipCountryNode = command.ipCountry.fold[NodeSeq](NodeSeq.Empty)(c => <ns2:IPCountry__c>{c.alpha2}</ns2:IPCountry__c>)
      val paymentNode = command.paymentMethod.fold[NodeSeq](NodeSeq.Empty)(h => XmlWriter.write(h).value)
      val promotionCodeNode =
        command.promoCode.fold[NodeSeq](NodeSeq.Empty)(code => <ns2:InitialPromotionCode__c>{code.get}</ns2:InitialPromotionCode__c>
        <ns2:PromotionCode__c>{code.get}</ns2:PromotionCode__c>)
      val supplierCodeNode = command.supplierCode.fold[NodeSeq](NodeSeq.Empty)(code => <ns2:SupplierCode__c>{code.get}</ns2:SupplierCode__c>)

      Writer(
        Map(
          "Salesforce ID" -> command.account.contactId.salesforceContactId,
          "Rate plan ID" -> command.ratePlans.head.productRatePlanId,
          "Current time" -> s"$now in sunny ${now.getZone.getID}",
          "Customer acceptance" -> command.contractAcceptance.toString,
          "Contract effective" -> command.contractEffective.toString,
        ),
        <ns1:subscribe>
        <ns1:subscribes>
          {XmlWriter.write(command.account).value}{paymentNode}
          <ns1:BillToContact xsi:type="ns2:Contact">
            <ns2:FirstName>{command.name.first}</ns2:FirstName>
            <ns2:LastName>{command.name.last}</ns2:LastName>
            <ns2:Address1>{command.address.lineOne}</ns2:Address1>
            <ns2:Address2>{command.address.lineTwo}</ns2:Address2>
            <ns2:City>{command.address.town}</ns2:City>
            <ns2:PostalCode>{command.address.postCode}</ns2:PostalCode>
            <ns2:State>{command.address.countyOrState}</ns2:State>
            <ns2:Country>{command.address.country.fold(command.address.countryName)(_.alpha2)}</ns2:Country>
            <ns2:WorkEmail>{command.email}</ns2:WorkEmail>
            {
          command.phone.map(phone => <ns2:WorkPhone>{phone.format}</ns2:WorkPhone>).getOrElse(NodeSeq.Empty)
        }{
          command.name.title.map(title => <ns2:Title__c>{title.title}</ns2:Title__c>).getOrElse(NodeSeq.Empty)
        }
          </ns1:BillToContact>
          <ns1:PreviewOptions>
            <ns1:EnablePreviewMode>false</ns1:EnablePreviewMode>
            <ns1:NumberOfPeriods>1</ns1:NumberOfPeriods>
          </ns1:PreviewOptions>
          {soldToContactNode}
          <ns1:SubscribeOptions>
            <ns1:GenerateInvoice>true</ns1:GenerateInvoice>
            <ns1:ProcessPayments>true</ns1:ProcessPayments>
          </ns1:SubscribeOptions>
          <ns1:SubscriptionData>
            <ns1:Subscription xsi:type="ns2:Subscription">
              <ns2:AutoRenew>true</ns2:AutoRenew>
              <ns2:ContractEffectiveDate>{command.contractEffective}</ns2:ContractEffectiveDate>
              <ns2:ContractAcceptanceDate>{command.contractAcceptance}</ns2:ContractAcceptanceDate>
              <ns2:InitialTerm>12</ns2:InitialTerm>
              <ns2:RenewalTerm>12</ns2:RenewalTerm>
              <ns2:TermStartDate>{command.contractEffective}</ns2:TermStartDate>
              <ns2:TermType>TERMED</ns2:TermType>
              <ns2:ReaderType__c>{command.readerType.value}</ns2:ReaderType__c>
              {promotionCodeNode}
              {supplierCodeNode}
              {ipCountryNode}
            </ns1:Subscription>{command.ratePlans.list.toList.map(ratePlan => XmlWriter.write(ratePlan).value)}
          </ns1:SubscriptionData>
        </ns1:subscribes>
      </ns1:subscribe>,
      )
    }