and nothing else: linking the purchase to a customer * record is BusPro's business. The attributes are echoed from GUTSCHEINZAHLUNGSARTEN. */ class VoucherSalePayloadBuilder { /** * @param string $saleType Constants::BOOKING_TYPE_INQUIRY for the dry run, Constants::BOOKING_TYPE_BOOKING for the purchase * * @return array */ public function buildSalePayload(VoucherPurchaseDto $dto, string $saleType): array { if (null === $dto->template || null === $dto->paymentMethod) { throw new \LogicException('A voucher sale needs a template and a payment method.'); } $communication = [ 'telefonprivat' => $dto->phone, 'email' => $dto->email, ]; // Not in the vendor's GUTSCHEINBUCHUNG example; the element name is the one BUCHUNG uses. if (null !== $dto->mobile && '' !== trim($dto->mobile)) { $communication['telefonmobil'] = $dto->mobile; } return [ 'buchungsart' => $saleType, 'gutscheinart' => $dto->template->type, 'idgutscheinvorlage' => $dto->template->id, 'kaeufer' => $dto->from, 'empfaenger' => $dto->to, 'kaufpreis' => $dto->amount, 'text' => '', 'rechnungsempfänger' => [ 'name' => $dto->lastName, 'vorname' => $dto->firstName, 'anrede' => $dto->salutation, 'titel' => $dto->title, 'geschlecht' => '', 'geburtsdatum' => '', 'anschrift' => $dto->address->toPayload(), 'kommunikation' => $communication, ], 'zahlung' => [ '@idzahlungsart' => $dto->paymentMethod->id, '@bezeichnung' => $dto->paymentMethod->label, '@art' => $dto->paymentMethod->type, ], ]; } /** * @return array */ public function buildPreviewPayload(VoucherPurchaseDto $dto): array { if (null === $dto->template) { throw new \LogicException('A voucher preview needs a template.'); } return [ 'idgutscheinvorlage' => $dto->template->id, 'kaeufer' => $dto->from, 'empfaenger' => $dto->to, 'kaufpreis' => $dto->amount, 'text' => '', ]; } }