private function buildReceiver( Receiver $receiver , AbstractPayPalMessageFactory $factory ) { $receiverAmount = $receiver->getAmount(); $receiverEmail = $receiver->getEmail(); $receiverInvoiceId = $receiver->getInvoiceId(); $receiverPaymentType = $receiver->getPaymentType(); $receiverPaymentSubType = $receiver->getPaymentSubType(); $receiverPhone = $receiver->getPhone(); $receiverPrimary = $receiver->isPrimary(); if ( $receiverEmail == null && $receiverPhone == null ) { throw new RuntimeException( 'You are *required* to specify the Receiver\'s email or the phone number.' ); } else { $receiverElement = $factory->createMessageElement(); $receiverElement->addChild( $factory->createMessageField( 'amount' , $factory->createMessagePrimitive( $receiverAmount ) ) ); if ( $receiverEmail != null ) { $receiverElement->addChild( $factory->createMessageField( 'email' , $factory->createMessagePrimitive( $receiverEmail ) ) ); } if ( $receiverInvoiceId != null ) { $receiverElement->addChild( $factory->createMessageField( 'invoiceId' , $factory->createMessagePrimitive( $receiverInvoiceId ) ) ); } if ( $receiverPaymentType != null ) { $receiverElement->addChild( $factory->createMessageField( 'paymentType' , $factory->createMessagePrimitive( $receiverPaymentType ) ) ); } if ( $receiverPaymentSubType != null ) { $receiverElement->addChild( $factory->createMessageField( 'paymentSubType' , $factory->createMessagePrimitive( $receiverPaymentSubType ) ) ); } if ( $receiverPhone != null ) { $receiverElement->addChild( $factory->createMessageField( 'phone' , $this->buildPhoneNumber( $receiverPhone , $factory ) ) ); } if ( $receiverPrimary != null ) { $receiverElement->addChild( $factory->createMessageField( 'primary' , $factory->createMessagePrimitive( $receiverPrimary ) ) ); } return $receiverElement; } }