-
Notifications
You must be signed in to change notification settings - Fork 4
Orders
For how to handle the exceptions correctly, see Exceptions.
The OrderService->get() method can extract all Order models.
The OrderService->include() method extracts model relation values.
use PlugAndPay\Sdk\Service\Client;
use PlugAndPay\Sdk\Service\OrderService;
use PlugAndPay\Sdk\Enum\OrderIncludes;
$client = new Client($token);
$service = new OrderService($client);
$orders = $service->include(
OrderIncludes::BILLING,
OrderIncludes::COMMENTS,
OrderIncludes::DISCOUNTS,
OrderIncludes::ITEMS,
OrderIncludes::PAYMENT,
OrderIncludes::TAGS,
OrderIncludes::TAXES,
)->get();
use PlugAndPay\Sdk\Service\Client;
use PlugAndPay\Sdk\Service\OrderService;
use PlugAndPay\Sdk\Filters\OrderFilter;
use PlugAndPay\Sdk\Enum\ContractType;
use PlugAndPay\Sdk\Enum\CountryCode;
use PlugAndPay\Sdk\Enum\Direction;
use PlugAndPay\Sdk\Enum\InvoiceStatus;
use PlugAndPay\Sdk\Enum\OrderMode;
use PlugAndPay\Sdk\Enum\PaymentStatus;
use PlugAndPay\Sdk\Enum\OrderSortType;
use PlugAndPay\Sdk\Enum\OrderSource;
$client = new Client($token);
$service = new OrderService($client);
$orders = $service->get(
(new OrderFilter())
->affiliateId(1234)
->checkoutId(1234)
->contractId(1234)
->contractType(ContractType::SUBSCRIPTION)
->country(CountryCode::from('NL'))
->direction(Direction::DESC)
->discountCode('discount-code')
->email('[email protected]')
->hasBump(true)
->hasTax(true)
->invoiceStatus(InvoiceStatus::FINAL)
->isDeleted(true)
->isFirst(true)
->isHidden(true)
->isUpsell(true)
->limit(1)
->mode(Mode::LIVE)
->page(2)
->paymentStatus(PaymentStatus::PAID)
->productId(1234)
->productTag('color-blue')
->query('Lorem Ipsum')
->sinceInvoiceDate(new DateTimeImmutable())
->sincePaidAt(new DateTimeImmutable())
->sort(OrderSortType::PAID_AT)
->source(Source::API)
->untilInvoiceDate(new DateTimeImmutable())
->untilPaidAt(new DateTimeImmutable())
);
The OrderService->find() method can extract a single Order model.
The OrderService->include() method extracts model relation values.
use PlugAndPay\Sdk\Service\Client;
use PlugAndPay\Sdk\Service\OrderService;
use PlugAndPay\Sdk\Enum\OrderIncludes;
$client = new Client($token);
$service = new OrderService($client);
$orderId = 1;
$order = $service->include(
OrderIncludes::BILLING,
OrderIncludes::COMMENTS,
OrderIncludes::DISCOUNTS,
OrderIncludes::ITEMS,
OrderIncludes::PAYMENT,
OrderIncludes::TAGS,
OrderIncludes::TAXES,
)->find($orderId);
$amount = $order->amount();
$amountWithTax = $order->amountWithTax();
$createdAt = $order->createdAt();
$deletedAt = $order->deletedAt();
$id = $order->id();
$invoiceNumber = $order->invoiceNumber();
$invoiceStatus = $order->invoiceStatus()->value;
$isFirst = $order->isFirst();
$isHidden = $order->isHidden();
$mode = $order->mode()->value;
$reference = $order->reference();
$source = $order->source()->value;
$updatedAt = $order->updatedAt();
The OrderService->create() method can store a single Order model to the Plug and Pay dashboard.
use PlugAndPay\Sdk\Service\Client;
use PlugAndPay\Sdk\Service\OrderService;
use PlugAndPay\Sdk\Enum\OrderIncludes;
use PlugAndPay\Sdk\Entity\Address;
use PlugAndPay\Sdk\Entity\Billing;
use PlugAndPay\Sdk\Entity\Comment;
use PlugAndPay\Sdk\Entity\Contact;
use PlugAndPay\Sdk\Entity\Item;
use PlugAndPay\Sdk\Entity\Order;
use PlugAndPay\Sdk\Entity\Payment;
use PlugAndPay\Sdk\Entity\Tax;
use PlugAndPay\Sdk\Entity\OrderBilling;
use PlugAndPay\Sdk\Entity\Discount;
use PlugAndPay\Sdk\Enum\OrderIncludes;
use PlugAndPay\Sdk\Enum\PaymentStatus;
use PlugAndPay\Sdk\Enum\PaymentProvider;
use PlugAndPay\Sdk\Enum\TaxExempt;
use PlugAndPay\Sdk\Enum\CountryCode;
use PlugAndPay\Sdk\Enum\PaymentType;
use PlugAndPay\Sdk\Enum\Source;
use PlugAndPay\Sdk\Enum\Mode;
use PlugAndPay\Sdk\Enum\PaymentMethod;
use PlugAndPay\Sdk\Enum\DiscountType;
use PlugAndPay\Sdk\Service\Client;
use PlugAndPay\Sdk\Service\OrderService;
$client = new Client($token);
$service = new OrderService($client);
$tax = (new Tax())->setRateId(1);
$payment = (new Payment)
->setCustomerId('customer-id')
->setMandateId('mandate-id')
->setMethod(PaymentMethod::APPLEPAY)
->setPaidAt(new DateTimeImmutable('2022-01-01'))
->setProvider(PaymentProvider::MOLLIE)
->setStatus(PaymentStatus::PAID)
->setTransactionId('mollie-transaction-id')
->setType(PaymentType::MANUAL)
->setUrl('https://www.payment-url.com');
$discount = (new Discount())
->setAmount(10)
->setCode('discount-code')
->setType(DiscountType::PROMOTION);
$itemOne = (new Item())->setProductId(1);
$itemTwo = (new Item())->setProductId(2);
$contact = (new Contact())
->setCompany('Plug&Pay')
->setEmail('[email protected]')
->setFirstName('test')
->setLastName('the tester')
->setTaxExempt(TaxExempt::REVERSE)
->setTelephone('06-89754785')
->setWebsite('https://www.plugandpay.nl');
$address = (new Address())
->setCity('Test')
->setCountry(CountryCode::NL)
->setStreet('teststreet')
->setHouseNumber('230-1')
->setZipcode('2323DD');
$commentOne = (new Comment())->setValue('Comment One');
$commentTwo = (new Comment())->setValue('Comment Two');
$billing = (new OrderBilling())
->setAddress($address)
->setContact($contact);
$order = (new Order)
->setAmount(100)
->setTotal(121)
->setBilling($billing)
->setComments([
$commentOne,
$commentTwo,
])
->setTotalDiscounts([$discount])
->setHidden(false)
->setItems([
$itemOne,
$itemTwo,
])
->setMode(Mode::TEST)
->setPayment($payment)
->setReference('123456789')
->setSource(Source::API)
->setTags([
'first',
'second',
'third',
'fourth',
])
->setTaxes([$tax]);
$order = $service->include(
OrderIncludes::BILLING,
OrderIncludes::COMMENTS,
OrderIncludes::DISCOUNTS,
OrderIncludes::ITEMS,
OrderIncludes::PAYMENT,
OrderIncludes::TAGS,
OrderIncludes::TAXES,
)->create($order);
$orderId = $order->id();
The OrderService->update() method can update a single Order model to the Plug and Pay dashboard.
use PlugAndPay\Sdk\Service\Client;
use PlugAndPay\Sdk\Service\OrderService;
use PlugAndPay\Sdk\Entity\Order;
use PlugAndPay\Sdk\Enum\OrderIncludes;
$client = new Client($token);
$service = new OrderService($client);
$orderId = 14;
$order = $service->include(
OrderIncludes::BILLING,
OrderIncludes::COMMENTS,
OrderIncludes::DISCOUNTS,
OrderIncludes::ITEMS,
OrderIncludes::PAYMENT,
OrderIncludes::TAGS,
OrderIncludes::TAXES,
)->update($orderId, function (Order $order) {
$order->setAmount(1000.00);
$order->setTotal(1210.00);
$order->setFirst(false);
$order->setHidden(true);
$order->setMode(Mode::LIVE);
$order->setReference('reference-code');
// Billing Address
$order->billing()->address()
->setCity('Test')
->setCountry(CountryCode::AL)
->setStreet('teststreet')
->setHouseNumber('200-1')
->setZipcode('1212DP');
// Billing Contact
$order->billing()->contact()
->setCompany('New Company')
->setEmail('[email protected]')
->setFirstName('First')
->setLastName('Last')
->setTelephone('06-12345678')
->setWebsite('https://www.new-website.com');
});
The OrderService->delete() method can delete a single Order model from the Plug and Pay dashboard.
On success: nothing is returned Not found: NotFoundException exception is thrown Not authenticated: UnauthenticatedException exception is thrown
use PlugAndPay\Sdk\Service\Client;
use PlugAndPay\Sdk\Service\OrderService;
$client = new Client($token);
$service = new OrderService($client);
$orderId = 12;
$service->delete($orderId);
By using the include method you can get more information. It is important that you only request the information you need.
use PlugAndPay\Sdk\Service\Client;
use PlugAndPay\Sdk\Service\OrderService;
use PlugAndPay\Sdk\Enum\OrderIncludes;
$client = new Client($token);
$service = new OrderService($client);
$orderId = 1;
$service->include(
OrderIncludes::BILLING,
OrderIncludes::COMMENTS,
OrderIncludes::DISCOUNTS,
OrderIncludes::ITEMS,
OrderIncludes::PAYMENT,
OrderIncludes::TAGS,
OrderIncludes::TAXES,
)->find($orderId);
use PlugAndPay\Sdk\Enum\OrderIncludes;
use PlugAndPay\Sdk\Service\Client;
use PlugAndPay\Sdk\Service\OrderService;
use PlugAndPay\Sdk\Enum\OrderIncludes;
$client = new Client($token);
$service = new OrderService($client);
$orderId = 1;
$order = $service->include(
OrderIncludes::BILLING
)->find($orderId);
$billing = $order->billing();
$company = $billing->company();
$email = $billing->email();
$firstName = $billing->firstName();
$lastName = $billing->lastName();
$telephone = $billing->telephone();
$website = $billing->website();
$city = $billing->address()->city();
$country = $billing->address()->country()->value;
$street = $billing->address()->street();
$houseNumber = $billing->address()->houseNumber();
$zipcode = $billing->address()->zipcode();
use PlugAndPay\Sdk\Service\Client;
use PlugAndPay\Sdk\Service\OrderService;
use PlugAndPay\Sdk\Enum\OrderIncludes;
$client = new Client($token);
$service = new OrderService($client);
$orderId = 1;
$order = $service->include(
OrderIncludes::COMMENTS
)->find($orderId);
$comment = $order->comments()[0];
$createdAt = $comment->createdAt();
$id = $comment->id();
$updatedAt = $comment->updatedAt();
$value = $comment->value();
use PlugAndPay\Sdk\Service\Client;
use PlugAndPay\Sdk\Service\OrderService;
use PlugAndPay\Sdk\Enum\OrderIncludes;
$client = new Client($token);
$service = new OrderService($client);
$orderId = 1;
$order = $service->include(
OrderIncludes::DISCOUNTS
)->find($orderId);
$discount = $order->totalDiscounts()[0];
// Or receive a discount from an item:
$discount = $order->items()[0]->discounts()[0];
$value = $discount->amount();
$code = $discount->code();
$type = $discount->type()->value;
use PlugAndPay\Sdk\Service\Client;
use PlugAndPay\Sdk\Service\OrderService;
use PlugAndPay\Sdk\Enum\OrderIncludes;
$client = new Client($token);
$service = new OrderService($client);
$orderId = 1;
$order = $service->include(
OrderIncludes::ITEMS
)->find($orderId);
$item = $order->items()[0];
$discount = $item->discounts()[0]->amount();
$discountCode = $item->discounts()[0]->code();
$id = $item->id();
$label = $item->label();
$productId = $item->productId();
$quantity = $item->quantity();
$amount = $item->amount();
$amountWithTax = $item->amountWithTax();
$amountWithTax = $item->type()->value;
use PlugAndPay\Sdk\Service\Client;
use PlugAndPay\Sdk\Service\OrderService;
use PlugAndPay\Sdk\Enum\OrderIncludes;
$client = new Client($token);
$service = new OrderService($client);
$orderId = 1;
$order = $service->include(
OrderIncludes::PAYMENT
)->find($orderId);
$payment = $order->payment();
$customerId = $payment->customerId();
$mandateId = $payment->mandateId();
$method = $payment->method()->value;
$orderId = $payment->orderId();
$paidAt = $payment->paidAt();
$provider = $payment->provider()->value;
$status = $payment->status()->value;
$transactionId = $payment->transactionId();
$type = $payment->type()->value;
$url = $payment->url();
use PlugAndPay\Sdk\Service\Client;
use PlugAndPay\Sdk\Service\OrderService;
use PlugAndPay\Sdk\Enum\OrderIncludes;
$client = new Client($token);
$service = new OrderService($client);
$orderId = 1;
$order = $service ->include(
OrderIncludes::TAGS
)->find($orderId);
$tags = $order->tags();
use PlugAndPay\Sdk\Service\Client;
use PlugAndPay\Sdk\Service\OrderService;
use PlugAndPay\Sdk\Enum\OrderIncludes;
$client = new Client($token);
$service = new OrderService($client);
$orderId = 1;
$order = $service->include(
OrderIncludes::TAXES
)->find($orderId);
// All taxes
$tax = $order->taxes()[0];
$tax->amount()
$tax->rate()->percentage()
// Tax per item
$item = $order->items()[0];
$itemTaxValue = $item->tax()->amount();
$itemTaxPercentage = $item->tax()->rate()->percentage();