-
Notifications
You must be signed in to change notification settings - Fork 4
Subscriptions
For how to handle the exceptions correctly, see Exceptions.
The SubscriptionService->get() method can extract all Order models.
The SubscriptionService->include() method extracts model relation values.
use PlugAndPay\Sdk\Service\Client;
use PlugAndPay\Sdk\Service\SubscriptionService;
use PlugAndPay\Sdk\Enum\SubscriptionIncludes;
$client = new Client($token);
$service = new SubscriptionService($client);
$subscriptions = $service->include(
SubscriptionIncludes::BILLING,
SubscriptionIncludes::PRICING,
SubscriptionIncludes::PRODUCT,
SubscriptionIncludes::TAGS,
SubscriptionIncludes::TRIAL,
)->get();
use PlugAndPay\Sdk\Service\Client;
use PlugAndPay\Sdk\Service\SubscriptionService;
use PlugAndPay\Sdk\Filters\SubscriptionFilter;
use PlugAndPay\Sdk\Enum\Interval;
use PlugAndPay\Sdk\Enum\CountryCode;
use PlugAndPay\Sdk\Enum\Mode;
use PlugAndPay\Sdk\Enum\SubscriptionStatus;
use PlugAndPay\Sdk\Enum\ContractType;
$client = new Client($token);
$service = new SubscriptionFilter($client);
$subscriptions = $service->get(
(new SubscriptionFilter)
->affiliateId(1234)
->billingScheduleInterval(Interval::MONTHLY)
->billingScheduleLatestAt(new DateTimeImmutable('2022-01-01'))
->billingScheduleNextAt(new DateTimeImmutable('2022-01-01'))
->country(CountryCode::NL)
->hasOrders(true)
->isTrial(true)
->limit(10)
->mode(Mode::TEST)
->page(1)
->productId(1)
->isFirst(true)
->query('Lorem ipsum')
->sinceCreatedAt(new DateTimeImmutable('2022-01-01'))
->status(SubscriptionStatus::ACTIVE)
->tag(['lorem'])
->type(ContractType::INSTALLMENTS)
->untilCreatedAt(new DateTimeImmutable('2022-01-01'))
);
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\SubscriptionService;
use PlugAndPay\Sdk\Enum\SubscriptionIncludes;
$client = new Client($token);
$service = new SubscriptionService($client);
$subscriptionId = 40;
$subscription = $service->include(
SubscriptionIncludes::BILLING,
SubscriptionIncludes::META,
SubscriptionIncludes::PRICING,
SubscriptionIncludes::PRODUCT,
SubscriptionIncludes::TAGS,
SubscriptionIncludes::TRIAL,
)->find($subscriptionId);
$id = $subscription->id();
$cancelledAt = $subscription->cancelledAt();
$createdAt = $subscription->createdAt();
$deletedAt = $subscription->deletedAt();
$mode = $subscription->mode()->value;
$pricing = $subscription->pricing();
$product = $subscription->product();
$status = $subscription->status();
$source = $subscription->source();
$billing = $subscription->billing();
$tags = $subscription->tags();
$trial = $subscription->trial();
The SubscriptionService->create() method can store a single Order model to the Plug and Pay dashboard.
use PlugAndPay\Sdk\Service\Client;
use PlugAndPay\Sdk\Service\SubscriptionService;
use PlugAndPay\Sdk\Enum\SubscriptionIncludes;
use PlugAndPay\Sdk\Entity\SubscriptionTrial;
use PlugAndPay\Sdk\Entity\SubscriptionPaymentOptions;
use PlugAndPay\Sdk\Entity\SubscriptionBillingSchedule;
use PlugAndPay\Sdk\Entity\Contact;
use PlugAndPay\Sdk\Entity\Address;
use PlugAndPay\Sdk\Entity\SubscriptionBilling;
use PlugAndPay\Sdk\Entity\Product;
use PlugAndPay\Sdk\Entity\TaxRate;
use PlugAndPay\Sdk\Entity\Discount;
use PlugAndPay\Sdk\Entity\SubscriptionPricing;
use PlugAndPay\Sdk\Entity\Subscription;
$client = new Client($token);
$service = new SubscriptionService($client);
$subscriptionTrial = (new SubscriptionTrial())
->setEndDate(new DateTimeImmutable('2022-12-01'))
->setIsActive(true)
->setStartDate(new DateTimeImmutable('2022-01-01'));
$paymentOptions = (new SubscriptionPaymentOptions())
->setCustomerId('customer-id')
->setProvider(PaymentProvider::MOLLIE)
->setTransactionId(123456789)
->setType(PaymentType::MANDATE)
->setIban('NL12ABNA0746352736')
->setName('Test the Tester');
$subscriptionSchedule = (new SubscriptionBillingSchedule())
->setInterval(Interval::MONTHLY)
->setLast(1)
->setLastAt(new DateTimeImmutable('2022-01-01'))
->setLatest(12)
->setLatestAt(new DateTimeImmutable('2022-12-01'))
->setNext(2)
->setNextAt(new DateTimeImmutable())
->setRemaining(11);
$contact = (new Contact)
->setCompany('Lorem')
->setEmail('[email protected]')
->setFirstName('First')
->setLastName('Last')
->setTelephone('06-12345678')
->setWebsite('https://www.lorem-ipsum.com');
$address = (new Address)
->setCity('Lorem')
->setCountry(CountryCode::NL)
->setStreet('Ipsum')
->setHouseNumber('420')
->setZipcode('1212DD');
$subscriptionBilling = (new SubscriptionBilling)
->setAddress($address)
->setContact($contact)
->setSchedule($subscriptionSchedule)
->setPaymentOptions($paymentOptions);
$product = (new Product)
->setId(6);
$rate = (new TaxRate)
->setId(57);
$discount = (new Discount())
->setAmount(100)
->setAmountWithTax(121.00)
->setCode('cool-code-123')
->setType(DiscountType::PROMOTION);
$pricing = (new SubscriptionPricing())
->setAmount(10.00)
->setDiscounts([$discount])
->setQuantity(10)
->setTax($tax)
->setIsTaxIncluded(false);
$subscription = (new Subscription())
->setMode(Mode::TEST)
->setPricing($pricing)
->setProduct($product)
->setStatus(SubscriptionStatus::ACTIVE)
->setSource(Source::API)
->setBilling($subscriptionBilling)
->setTags([
'first',
'second',
'third',
])
->setTrial($subscriptionTrial);
$subscription = $service->include(
SubscriptionIncludes::PRICING,
SubscriptionIncludes::BILLING,
SubscriptionIncludes::META,
SubscriptionIncludes::PRODUCT,
SubscriptionIncludes::TAGS,
SubscriptionIncludes::TRIAL,
)->create($subscription);
$subscriptionId = $subscription->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\SubscriptionService;
use PlugAndPay\Sdk\Entity\Subscription;
use PlugAndPay\Sdk\Enum\Mode;
use PlugAndPay\Sdk\Enum\SubscriptionStatus;
use PlugAndPay\Sdk\Enum\Source;
use PlugAndPay\Sdk\Enum\CountryCode;
use PlugAndPay\Sdk\Enum\PaymentProvider;
use PlugAndPay\Sdk\Enum\PaymentType;
$client = new Client($token);
$service = new SubscriptionService($client);
$subscriptionId = 1;
$subscription = $service->update($subscriptionId, function (Subscription $subscription) {
$subscription->setMode(Mode::LIVE);
$subscription->setTags([
'first',
'second',
'third'
]);
$subscription->setStatus(SubscriptionStatus::ACTIVE);
$subscription->setSource(Source::API);
// Pricing
$subscription->pricing()
->setAmount(100.00)
->setQuantity(10)
->tax()
->setAmount(100)
->rate()->setId(10);
// Product
$subscription->product()->setId(6);
// Billing address
$subscription->billing()->address()
->setCity('lorem')
->setCountry(CountryCode::BE)
->setStreet('testing')
->setHouseNumber('230-1')
->setZipcode('1212DD');
// Billing contact
$subscription->billing()->contact()
->setCompany('test')
->setEmail('[email protected]')
->setFirstName('First')
->setLastName('Name')
->setTelephone('03464646146')
->setWebsite('test.com');
// Billing schedule
$subscription->billing()->schedule()
->setInterval(Interval::MONTHLY)
->setLast(12)
->setLastAt(new DateTimeImmutable('2022-01-01'))
->setLatest(1)
->setLatestAt(new DateTimeImmutable('2022-02-01'))
->setNext(1)
->setNextAt(new DateTimeImmutable())
->setRemaining(54);
// Billing payment options
$subscription->billing()->paymentOptions()
->setCustomerId('asdasd')
->setProvider(PaymentProvider::MOLLIE)
->setTransactionId(12345)
->setType(PaymentType::MANDATE)
->setIban('NL18RABO0123459876')
->setName('Test the Tester');
// Trial
$subscription->trial()
->setEndDate(new DateTimeImmutable('2022-12-01'))
->setIsActive(true)
->setEndDate(new DateTimeImmutable('2022-01-01'));
});
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\SubscriptionService;
$client = new Client($token);
$service = new SubscriptionService($client);
$subscriptionId = 2;
$service->delete($subscriptionId);
By using the include method you can get more information. It is important that you only request the information you need.
use PlugAndPay\Sdk\Enum\SubscriptionIncludes;
use PlugAndPay\Sdk\Service\Client;
use PlugAndPay\Sdk\Service\SusbcriptionService;
$client = new Client($token);
$service = new SusbcriptionService($client);
$service->include(
SubscriptionIncludes::PRICING,
SubscriptionIncludes::BILLING,
SubscriptionIncludes::META,
SubscriptionIncludes::PRODUCT,
SubscriptionIncludes::TAGS,
SubscriptionIncludes::TRIAL,
);
use PlugAndPay\Sdk\Service\Client;
use PlugAndPay\Sdk\Service\SubscriptionService;
use PlugAndPay\Sdk\Enum\SubscriptionIncludes;
$client = new Client($token);
$service = new SubscriptionService($client);
$subscriptionId = 1;
$subscription = $service->include(
SubscriptionIncludes::BILLING
)->find($subscriptionId);
$address = $subscription->address();
$city = $address->city();
$country = $address->country()->value;
$street = $address->street();
$houseNumber = $address->houseNumber();
$zipcode = $address->zipCode();
$contact = $subscription->contact();
$company = $contact->company();
$email = $contact->email();
$firstName = $contact->firstName();
$lastName = $contact->lastName();
$telephone = $contact->telephone();
$vatIdNumber = $contact->vatIdNumber();
$website = $contact->website();
$schedule = $subscription->schedule();
$interval = $schedule->interal()->value;
$last = $schedule->last();
$lastAt = $schedule->lastAt()->format;
$latest = $schedule->latest();
$latestAt = $schedule->latestAt()->format;
$next = $schedule->next();
$nextAt = $schedule->nextAt()->format;
$remaining = $schedule->remaining();
$terminationAt = $schedule->terminationAt()->format;
$paymentOptions = $subscription->paymentOptions();
$customerId = $paymentOptions->customerId();
$mandateId = $paymentOptions->mandateId();
$provider = $paymentOptions->provider()->value;
$transactionId = $paymentOptions->transactionId();
$type = $paymentOptions->type()->value;
$iban = $paymentOptions->iban();
$name = $paymentOptions->name();
use PlugAndPay\Sdk\Service\Client;
use PlugAndPay\Sdk\Service\SubscriptionService;
use PlugAndPay\Sdk\Enum\SubscriptionIncludes;
$client = new Client($token);
$service = new SubscriptionService($client);
$subscriptionId = 1;
$subscription = $service=->include(
SubscriptionIncludes::PRICING
)->find($subscriptionId);
$pricing = $subscription->pricing();
$amount = $pricing->amount();
$amountWithTax = $pricing->amountWithTax();
$discounts = $pricing->discounts();
$quantity = $pricing->quantity();
$tax = $pricing->tax();
$isTaxIncluded = $pricing->isTaxIncluded();
use PlugAndPay\Sdk\Enum\SubscriptionIncludes;
use PlugAndPay\Sdk\Service\Client;
use PlugAndPay\Sdk\Service\SubscriptionService;
$client = new Client($token);
$service = new SubscriptionService($client);
$subscriptionId = 1;
$subscription = $service->include(
SubscriptionIncludes::PRODUCT
)->find($subscriptionId);
$product = $subscription->product();
$id = $product->id();
$createdAt = $product->createdAt()->format();
$deletedAt = $product->deletedAt()->format();
$updatedAt = $product->updatedAt()->format();
$description = $product->description();
$ledger = $product->ledger();
$physical = $product->physical();
$pricing = $product->pricing();
$publicTitle = $product->publicTitle();
$sku = $product->sku();
$slug = $product->slug();
$stock = $product->stock();
$title = $product->title();
$type = $product->type()->value;
$type = $product->type()->value;
use PlugAndPay\Sdk\Service\Client;
use PlugAndPay\Sdk\Service\SubscriptionService;
use PlugAndPay\Sdk\Enum\SubscriptionIncludes;
$client = new Client($token);
$service = new SubscriptionService($client);
$subscriptionId = 1;
$subscription = $service->include(
SubscriptionIncludes::TAGS
)->find($subscriptionId);
$tags = $subscription->tags();
use PlugAndPay\Sdk\Service\Client;
use PlugAndPay\Sdk\Service\SubscriptionService;
use PlugAndPay\Sdk\Enum\SubscriptionIncludes;
$client = new Client($token);
$service = new SubscriptionService($client);
$subscriptionId = 1;
$subscription = $service->include(
SubscriptionIncludes::TRIAL
)->find($subscriptionId);
$trial = $subscription->trial();
$startDate = $trial->endDate()->startDate;
$endDate = $trial->endDate()->format;
$isActive = $trial->isActive();