@@ -48,100 +48,97 @@ use Lloricode\Paymaya\DataTransferObjects\Checkout\MetaDataDto;
4848use Lloricode\Paymaya\DataTransferObjects\Checkout\RedirectUrlDto;
4949use Lloricode\Paymaya\DataTransferObjects\Checkout\TotalAmountDto;
5050use Lloricode\Paymaya\Enums\Environment;
51- use Lloricode\Paymaya\Requests\RetrieveCheckoutRequest;
52- use Lloricode\Paymaya\Requests\SubmitCheckoutRequest;
51+ use Lloricode\Paymaya\Requests\Checkout\ RetrieveCheckoutRequest;
52+ use Lloricode\Paymaya\Requests\Checkout\ SubmitCheckoutRequest;
5353
5454Constant::$environment = Environment::sandbox;
5555Constant::$secretKey = 'sk-X8qolYjy62kIzEbr0QRK1h4b4KDVHaNcwMYk39jInSl';
5656Constant::$publicKey = 'pk-Z0OSzLvIcOI2UIvDhdTGVVfRSSeiGStnceqwUE7n0Ah';
5757
58- $checkout = (new CheckoutDto)
59- ->setTotalAmount(
60- (new TotalAmountDto)
61- ->setValue(100)
62- ->setDetails((new AmountDetailDto)->setSubtotal(100))
63- )
64- ->setBuyer(
65- (new BuyerDto)
66- ->setFirstName('John')
67- ->setMiddleName('Paul')
68- ->setLastName('Doe')
69- ->setBirthday('1995-10-24')
70- ->setCustomerSince('1995-10-24')
71- ->setGender('M')
72- ->setContact(
73- (new ContactDto)
74- ->setPhone('+639181008888')
75- ->setEmail('merchant@merchantsite.com')
76- )
77- ->setShippingAddress(
78- (new ShippingAddressDto)
79- ->setFirstName('John')
80- ->setMiddleName('Paul')
81- ->setLastName('Doe')
82- ->setPhone('+639181008888')
83- ->setEmail('merchant@merchantsite.com')
84- ->setLine1('6F Launchpad')
85- ->setLine2('Reliance Street')
86- ->setCity('Mandaluyong City')
87- ->setState('Metro Manila')
88- ->setZipCode('1552')
89- ->setCountryCode('PH')
90- ->setShippingType('ST')
91- )
92- ->setBillingAddress(
93- (new BillingAddressDto)
94- ->setLine1('6F Launchpad')
95- ->setLine2('Reliance Street')
96- ->setCity('Mandaluyong City')
97- ->setState('Metro Manila')
98- ->setZipCode('1552')
99- ->setCountryCode('PH')
100- )
101- )
102- ->addItem(
103- (new ItemDto)
104- ->setName('Canvas Slip Ons')
105- ->setQuantity(1)
106- ->setCode('CVG-096732')
107- ->setDescription('Shoes')
108- ->setAmount(
109- (new AmountDto)->setValue(100)->setDetails(
110- (new AmountDetailDto)
111- ->setDiscount(0)
112- ->setServiceCharge(0)
113- ->setShippingFee(0)
114- ->setTax(0)
115- ->setSubtotal(100)
58+ $checkout = new CheckoutDto(
59+ totalAmount: new TotalAmountDto(
60+ value: 100,
61+ details: new AmountDetailDto(
62+ subtotal: 100
63+ )
64+ ),
65+ buyer: new BuyerDto(
66+ firstName: 'John',
67+ middleName: 'Paul',
68+ lastName: 'Doe',
69+ birthday: '1995-10-24',
70+ customerSince: '1995-10-24',
71+ gender: 'M',
72+ contact: new ContactDto(
73+ phone: '+639181008888',
74+ email: 'merchant@merchantsite.com'
75+ ),
76+ shippingAddress: new ShippingAddressDto(
77+ firstName: 'John',
78+ middleName: 'Paul',
79+ lastName: 'Doe',
80+ phone: '+639181008888',
81+ email: 'merchant@merchantsite.com',
82+ line1: '6F Launchpad',
83+ line2: 'Reliance Street',
84+ city: 'Mandaluyong City',
85+ state: 'Metro Manila',
86+ zipCode: '1552',
87+ countryCode: 'PH',
88+ shippingType: 'ST'
89+ ),
90+ billingAddress: new BillingAddressDto(
91+ line1: '6F Launchpad',
92+ line2: 'Reliance Street',
93+ city: 'Mandaluyong City',
94+ state: 'Metro Manila',
95+ zipCode: '1552',
96+ countryCode: 'PH'
97+ )
98+ ),
99+ items: [
100+ new ItemDto(
101+ name: 'Canvas Slip Ons',
102+ quantity: 1,
103+ code: 'CVG-096732',
104+ description: 'Shoes',
105+ amount: new AmountDto(
106+ value: 100,
107+ details: new AmountDetailDto(
108+ discount: 0,
109+ serviceCharge: 0,
110+ shippingFee: 0,
111+ tax: 0,
112+ subtotal: 100
116113 )
117- )
118- ->setTotalAmount (
119- (new AmountDto)->setValue( 100)->setDetails(
120- ( new AmountDetailDto)
121- ->setDiscount(0)
122- ->setServiceCharge(0)
123- ->setShippingFee(0)
124- ->setTax(0)
125- ->setSubtotal( 100)
114+ ),
115+ totalAmount: new AmountDto (
116+ value: 100,
117+ details: new AmountDetailDto(
118+ discount: 0,
119+ serviceCharge: 0,
120+ shippingFee: 0,
121+ tax: 0,
122+ subtotal: 100
126123 )
127124 )
125+ ),
126+ ],
127+ redirectUrl: new RedirectUrlDto(
128+ success: 'https://www.merchantsite.com/success',
129+ failure: 'https://www.merchantsite.com/failure',
130+ cancel: 'https://www.merchantsite.com/cancel'
131+ ),
132+ requestReferenceNumber: '1551191039',
133+ metadata: new MetaDataDto(
134+ smi: 'smi',
135+ smn: 'smn',
136+ mci: 'mci',
137+ mpc: 'mpc',
138+ mco: 'mco',
139+ mst: 'mst'
128140 )
129- ->setRedirectUrl(
130- (new RedirectUrlDto)
131- ->setSuccess('https://www.merchantsite.com/success')
132- ->setFailure('https://www.merchantsite.com/failure')
133- ->setCancel('https://www.merchantsite.com/cancel')
134- )
135- ->setRequestReferenceNumber('1551191039')
136- ->setMetadata(
137- (new MetaDataDto)
138- ->setSMI('smi')
139- ->setSMN('smn')
140- ->setMCI('mci')
141- ->setMPC('mpc')
142- ->setMCO('mco')
143- ->setMST('mst')
144- );
141+ );
145142
146143// submit
147144$checkoutResponse = (new SubmitCheckoutRequest($checkout))->send()->dto();
@@ -169,14 +166,15 @@ Constant::$environment = Environment::sandbox;
169166Constant::$secretKey = 'sk-X8qolYjy62kIzEbr0QRK1h4b4KDVHaNcwMYk39jInSl';
170167Constant::$publicKey = 'pk-Z0OSzLvIcOI2UIvDhdTGVVfRSSeiGStnceqwUE7n0Ah';
171168
172- // register
169+ // register (readonly DTO via constructor)
173170(new RegisterCustomizationRequest(
174- (new CustomizationDto)
175- ->setLogoUrl('https://image-logo.png')
176- ->setIconUrl('https://image-icon.png')
177- ->setAppleTouchIconUrl('https://image-apple.png')
178- ->setCustomTitle('Test Title Mock')
179- ->setColorScheme('#e01c44')
171+ new CustomizationDto(
172+ logoUrl: 'https://image-logo.png',
173+ iconUrl: 'https://image-icon.png',
174+ appleTouchIconUrl: 'https://image-apple.png',
175+ customTitle: 'Test Title Mock',
176+ colorScheme: '#e01c44',
177+ )
180178))
181179 ->send()
182180 ->dto();
@@ -215,31 +213,37 @@ foreach ($webhooks as $webhook) {
215213 (new DeleteWebhookRequest($webhook->id))->send();
216214}
217215
218- // register
216+ // register (readonly DTOs via constructors)
219217(new RegisterWebhookRequest(
220- (new WebhookDto)
221- ->setName(Webhook::CHECKOUT_SUCCESS)
222- ->setCallbackUrl('https://web.test/test/success')
218+ new WebhookDto(
219+ name: Webhook::CHECKOUT_SUCCESS,
220+ callbackUrl: 'https://web.test/test/success'
221+ )
223222))->send();
224223
225224(new RegisterWebhookRequest(
226- (new WebhookDto)
227- ->setName(Webhook::CHECKOUT_FAILURE)
228- ->setCallbackUrl('https://web.test/test/failure')
225+ new WebhookDto(
226+ name: Webhook::CHECKOUT_FAILURE,
227+ callbackUrl: 'https://web.test/test/failure'
228+ )
229229))->send();
230230
231231(new RegisterWebhookRequest(
232- (new WebhookDto)
233- ->setName(Webhook::CHECKOUT_DROPOUT)
234- ->setCallbackUrl('https://web.test/test/drop')
232+ new WebhookDto(
233+ name: Webhook::CHECKOUT_DROPOUT,
234+ callbackUrl: 'https://web.test/test/drop'
235+ )
235236))->send();
236237
237- // update
238- $webhooks = (new UpdateWebhookRequest(
239- $webhooks[Webhook::CHECKOUT_SUCCESS]->setCallbackUrl(
240- 'https://web.test/test/update-success'
241- )
242- ))
238+ // update (create a new readonly DTO with the existing id and new callback URL)
239+ $existing = $webhooks[Webhook::CHECKOUT_SUCCESS];
240+ $updatedDto = new WebhookDto(
241+ id: $existing->id,
242+ name: $existing->name,
243+ callbackUrl: 'https://web.test/test/update-success'
244+ );
245+
246+ $webhooks = (new UpdateWebhookRequest($updatedDto))
243247 ->send()
244248 ->dto();
245249
0 commit comments