### Install Moka PHP Client and Initialize MokaClient Source: https://context7.com/optimisthub/moka-php/llms.txt Install the Moka PHP client using Composer. Initialize MokaClient with dealer credentials, optionally specifying the baseUrl for the test environment. ```php // Install via Composer // composer require moka/moka-php require_once('vendor/autoload.php'); // Live environment (default) $moka = new Moka\MokaClient([ 'dealerCode' => 'YOUR_DEALER_CODE', 'username' => 'YOUR_USERNAME', 'password' => 'YOUR_PASSWORD', ]); // Test/sandbox environment $moka = new Moka\ MokaClient([ 'dealerCode' => 'YOUR_DEALER_CODE', 'username' => 'YOUR_USERNAME', 'password' => 'YOUR_PASSWORD', 'baseUrl' => 'https://service.refmoka.com', ]); ``` -------------------------------- ### Install Moka PHP Client via Composer Source: https://github.com/optimisthub/moka-php/blob/master/README.md Use Composer to install the Moka PHP client library. This is the recommended method for managing dependencies. ```bash composer require moka/moka-php ``` -------------------------------- ### retrieveInstallmentInfo Source: https://context7.com/optimisthub/moka-php/llms.txt Returns the installment options and amounts for a given BIN/card. This method posts to the /PaymentDealer/DoCalcPaymentTable endpoint. ```APIDOC ## `payments()->retrieveInstallmentInfo()` — Get Installment Table ### Description Returns the installment options and amounts for a BIN/card. ### Method POST ### Endpoint /PaymentDealer/DoCalcPaymentTable ### Parameters #### Request Body - **binNumber** (string) - Required - The BIN number of the card. - **currency** (string) - Required - The currency code (e.g., 'TL'). - **orderAmount** (float) - Required - The total order amount. - **isThreeD** (integer) - Required - Flag to indicate if 3D Secure is used (1 for yes, 0 for no). - **isIncludedCommissionAmount** (integer) - Required - Flag to indicate if commission amount is included (1 for yes, 0 for no). ### Request Example ```php $request = new \Moka\Model\RetrieveInstallmentInfoRequest(); $request->setBinNumber('453144'); $request->setCurrency('TL'); $request->setOrderAmount(100.00); $request->setIsThreeD(1); $request->setIsIncludedCommissionAmount(1); $response = $moka->payments()->retrieveInstallmentInfo($request); ``` ### Response #### Success Response (200) - **resultCode** (string) - Indicates the result of the operation ('Success' or an error code). - **data** (array) - An array of installment options and their details. ``` -------------------------------- ### Get Installment Table Information Source: https://context7.com/optimisthub/moka-php/llms.txt Returns available installment options and their corresponding amounts for a given BIN number, currency, and order amount. Can specify if 3D Secure is required and if commission amounts should be included. ```php $request = new \Moka\Model\RetrieveInstallmentInfoRequest(); $request->setBinNumber('453144'); $request->setCurrency('TL'); $request->setOrderAmount(100.00); $request->setIsThreeD(1); $request->setIsIncludedCommissionAmount(1); $response = $moka->payments()->retrieveInstallmentInfo($request); print_r($response->getData()); // Array of installment options ``` -------------------------------- ### Client Initialization Source: https://context7.com/optimisthub/moka-php/llms.txt Install the Moka PHP client via Composer and initialize the MokaClient with your dealer credentials. You can switch between live and test environments using the 'baseUrl' option. ```APIDOC ## Installation and Client Initialization Install via Composer and instantiate `MokaClient` with your dealer credentials. Use `baseUrl` to switch between live and test environments. ```php // Install via Composer // composer require moka/moka-php require_once('vendor/autoload.php'); // Live environment (default) $moka = new \Moka\MokaClient([ 'dealerCode' => 'YOUR_DEALER_CODE', 'username' => 'YOUR_USERNAME', 'password' => 'YOUR_PASSWORD', ]); // Test/sandbox environment $moka = new \Moka\MokaClient([ 'dealerCode' => 'YOUR_DEALER_CODE', 'username' => 'YOUR_USERNAME', 'password' => 'YOUR_PASSWORD', 'baseUrl' => 'https://service.refmoka.com', ]); ``` ``` -------------------------------- ### Include Manual Installation Autoloader Source: https://github.com/optimisthub/moka-php/blob/master/README.md If not using Composer, include the autoloader file provided with the manual download of the Moka PHP client. ```php require_once('autoload.php'); ``` -------------------------------- ### Include Composer Autoloader Source: https://github.com/optimisthub/moka-php/blob/master/README.md After installing via Composer, include the autoloader to make the Moka client classes available in your project. ```php require_once('vendor/autoload.php'); ``` -------------------------------- ### Manage Payment Plans Source: https://context7.com/optimisthub/moka-php/llms.txt Handles the creation, listing, retrieval, updating, and deletion of recurring payment plans. Use `create` for new plans, `all` to list existing ones, `retrieve` for a specific plan, `update` to modify, and `delete` to remove. `retrieveHistory` can be used to get the history of a specific payment plan. ```php // Create payment plan $createPlan = new \Moka\Model\CreatePaymentPlanRequest(); $createPlan->setSaleId(55566); $createPlan->setTotalAmount(1200.00); $createPlan->setInstallmentCount(12); $createPlan->setFirstInstallmentDate('2024-02-01'); $createPlan->setCurrency('TL'); $response = $moka->paymentPlans()->create($createPlan); $planId = $response->getData(); // List plans $listReq = new \Moka\Model\RetrievePaymentPlanListRequest(); $listReq->setSaleId(55566); $plans = $moka->paymentPlans()->all($listReq); print_r($plans->getData()); // Get plan history $histReq = new \Moka\Model\RetrievePaymentPlanHistoryListRequest(); $histReq->setPaymentPlanId($planId); $history = $moka->paymentPlans()->retrieveHistory($histReq); print_r($history->getData()); ``` -------------------------------- ### Calculate Payment Amount Source: https://context7.com/optimisthub/moka-php/llms.txt Calculates the total amount due for a given installment scenario, including any applicable fees. Requires the base amount, installment number, and currency. ```php $request = new \Moka\Model\RetrievePaymentAmountRequest(); $request->setAmount(500.00); $request->setInstallmentNumber(3); $request->setCurrency('TL'); $response = $moka->payments()->retrieveAmount($request); echo 'Total with fees: '; print_r($response->getData()); ``` -------------------------------- ### Initiate Mobile 3DS Payment Source: https://context7.com/optimisthub/moka-php/llms.txt Use this to start a 3DS payment flow optimized for mobile applications. Ensure all required fields for the payment request are populated. ```php $request = new \Moka\Model\CreateMobilePaymentRequest(); $request->setCardHolderFullName('Jane Doe'); $request->setCardNumber('5127541122223332'); $request->setExpMonth('08'); $request->setExpYear('2026'); $request->setCvcNumber('456'); $request->setAmount(75.00); $request->setCurrency('TL'); $request->setInstallmentNumber(1); $request->setClientIp('10.0.0.5'); $request->setOtherTrxCode('MOB-' . time()); $response = $moka->payments()->createThreedsMobile($request); echo $response->getResultCode(); // 'Success' or error code ``` -------------------------------- ### retrieveAmount Source: https://context7.com/optimisthub/moka-php/llms.txt Calculates the total amount due for a given installment scenario. This method posts to the /PaymentDealer/DoCalcPaymentAmount endpoint. ```APIDOC ## `payments()->retrieveAmount()` — Calculate Payment Amount ### Description Calculates the total amount due for a given installment scenario. ### Method POST ### Endpoint /PaymentDealer/DoCalcPaymentAmount ### Parameters #### Request Body - **amount** (float) - Required - The base amount. - **installmentNumber** (integer) - Required - The number of installments. - **currency** (string) - Required - The currency code (e.g., 'TL'). ### Request Example ```php $request = new \Moka\Model\RetrievePaymentAmountRequest(); $request->setAmount(500.00); $request->setInstallmentNumber(3); $request->setCurrency('TL'); $response = $moka->payments()->retrieveAmount($request); ``` ### Response #### Success Response (200) - **resultCode** (string) - Indicates the result of the operation ('Success' or an error code). - **data** (object) - Contains the calculated total amount with fees. ``` -------------------------------- ### Payment Plans Management Source: https://context7.com/optimisthub/moka-php/llms.txt Manage recurring payment plans (installment agreements) including creation, retrieval, update, and deletion. ```APIDOC ## `paymentPlans()->create()` — Create Payment Plan ### Description Creates a new recurring payment plan. ### Method POST ### Endpoint `/PaymentDealer/CreatePaymentPlan` (Assumed based on context) ### Request Body - **saleId** (int) - Required - The ID of the associated sale. - **totalAmount** (float) - Required - The total amount for the plan. - **installmentCount** (int) - Required - The number of installments. - **firstInstallmentDate** (string) - Required - The date of the first installment (YYYY-MM-DD). - **currency** (string) - Required - The currency code. ### Request Example ```php $createPlan = new \Moka\Model\CreatePaymentPlanRequest(); $createPlan->setSaleId(55566); $createPlan->setTotalAmount(1200.00); $createPlan->setInstallmentCount(12); $createPlan->setFirstInstallmentDate('2024-02-01'); $createPlan->setCurrency('TL'); $response = $moka->paymentPlans()->create($createPlan); ``` ### Response #### Success Response (200) - **data** (int) - The ID of the created payment plan. - **resultCode** (string) - Indicates the result of the operation ('Success' or 'Error'). ``` ```APIDOC ## `paymentPlans()->all()` — List Payment Plans ### Description Retrieves a list of payment plans associated with a sale. ### Method GET ### Endpoint `/PaymentDealer/RetrievePaymentPlanList` (Assumed based on context) ### Request Body - **saleId** (int) - Required - The ID of the sale to filter plans by. ### Request Example ```php $listReq = new \Moka\Model\RetrievePaymentPlanListRequest(); $listReq->setSaleId(55566); $plans = $moka->paymentPlans()->all($listReq); ``` ### Response #### Success Response (200) - **data** (array) - A list of payment plans. - **resultCode** (string) - Indicates the result of the operation ('Success' or 'Error'). ``` ```APIDOC ## `paymentPlans()->retrieve()` — Retrieve Payment Plan ### Description Retrieves details of a specific payment plan. ### Method GET ### Endpoint `/PaymentDealer/RetrievePaymentPlan` (Assumed based on context) ### Request Body - **paymentPlanId** (int) - Required - The ID of the payment plan to retrieve. ### Request Example ```php $retrievePlan = new \Moka\Model\RetrievePaymentPlanRequest(); $retrievePlan->setPaymentPlanId($planId); $planDetails = $moka->paymentPlans()->retrieve($retrievePlan); ``` ### Response #### Success Response (200) - **data** (object) - Details of the payment plan. - **resultCode** (string) - Indicates the result of the operation ('Success' or 'Error'). ``` ```APIDOC ## `paymentPlans()->update()` — Update Payment Plan ### Description Updates an existing recurring payment plan. ### Method PUT ### Endpoint `/PaymentDealer/UpdatePaymentPlan` (Assumed based on context) ### Request Body - **paymentPlanId** (int) - Required - The ID of the payment plan to update. - **installmentCount** (int) - Optional - The new number of installments. - **firstInstallmentDate** (string) - Optional - The new date for the first installment (YYYY-MM-DD). ### Request Example ```php $updatePlan = new \Moka\Model\UpdatePaymentPlanRequest(); $updatePlan->setPaymentPlanId($planId); $updatePlan->setInstallmentCount(10); $moka->paymentPlans()->update($updatePlan); ``` ### Response #### Success Response (200) - **resultCode** (string) - Indicates the result of the operation ('Success' or 'Error'). ``` ```APIDOC ## `paymentPlans()->delete()` — Delete Payment Plan ### Description Deletes a recurring payment plan. ### Method DELETE ### Endpoint `/PaymentDealer/DeletePaymentPlan` (Assumed based on context) ### Request Body - **paymentPlanId** (int) - Required - The ID of the payment plan to delete. ### Request Example ```php $deletePlan = new \Moka\Model\DeletePaymentPlanRequest(); $deletePlan->setPaymentPlanId($planId); $moka->paymentPlans()->delete($deletePlan); ``` ### Response #### Success Response (200) - **resultCode** (string) - Indicates the result of the operation ('Success' or 'Error'). ``` ```APIDOC ## `paymentPlans()->retrieveHistory()` — Retrieve Payment Plan History ### Description Retrieves the history of a specific payment plan. ### Method GET ### Endpoint `/PaymentDealer/RetrievePaymentPlanHistoryList` (Assumed based on context) ### Request Body - **paymentPlanId** (int) - Required - The ID of the payment plan to retrieve history for. ### Request Example ```php $histReq = new \Moka\Model\RetrievePaymentPlanHistoryListRequest(); $histReq->setPaymentPlanId($planId); $history = $moka->paymentPlans()->retrieveHistory($histReq); ``` ### Response #### Success Response (200) - **data** (array) - A list of historical payment records for the plan. - **resultCode** (string) - Indicates the result of the operation ('Success' or 'Error'). ``` -------------------------------- ### List Payments Source: https://context7.com/optimisthub/moka-php/llms.txt Retrieves a list of payments, typically filtered by a date range. Ensure the start and end dates are in the correct 'YYYY-MM-DD' format. ```php $request = new \Moka\Model\RetrievePaymentListRequest(); $request->setStartDate('2024-01-01'); $request->setEndDate('2024-01-31'); $response = $moka->payments()->all($request); print_r($response->getData()); ``` -------------------------------- ### Unified API Response Object Source: https://context7.com/optimisthub/moka-php/llms.txt Handles API responses consistently, providing access to raw content, parsed data, result codes, messages, and exceptions. Includes an example error handling pattern. ```php $response = $moka->payments()->create($request); // Raw JSON string from the API $raw = $response->getContent(); // Parsed response payload (stdClass or null) $data = $response->getData(); // Result code string, e.g., 'Success', 'PaymentDealer.DoDirectPayment.InvalidRequest' $code = $response->getResultCode(); // Human-readable result message $message = $response->getResultMessage(); // Exception detail when an error occurs $exception = $response->getException(); // Example error handling pattern if ($response->getResultCode() !== 'Success') { error_log('Moka API error: ' . $response->getResultCode() . ' - ' . $response->getResultMessage() . ' | Exception: ' . $response->getException()); throw new \RuntimeException('Payment failed: ' . $response->getResultMessage()); } ``` -------------------------------- ### Initialize Moka Client (Live Environment) Source: https://github.com/optimisthub/moka-php/blob/master/README.md Instantiate the MokaClient with your credentials to connect to the live Moka API environment. Ensure you have your 'dealerCode', 'username', and 'password'. ```php $moka = new \Moka\MokaClient([ 'dealerCode' => 'xxx', 'username' => 'xxx', 'password' => 'xxx', ]); ``` -------------------------------- ### Initialize Moka Client (Test Environment) Source: https://github.com/optimisthub/moka-php/blob/master/README.md Initialize the MokaClient specifying the test environment URL to avoid processing live transactions during development. Use your credentials and set the 'baseUrl' to the test endpoint. ```php $moka = new \Moka\MokaClient([ 'dealerCode' => 'xxx', 'username' => 'xxx', 'password' => 'xxx', 'baseUrl' => 'https://service.refmoka.com' ]); ``` -------------------------------- ### Create Customer with Card Source: https://context7.com/optimisthub/moka-php/llms.txt Creates a customer and simultaneously saves a tokenized card. This requires customer details along with full cardholder name, card number, and expiration date. ```php $request = new \Moka\Model\CreateCustomerWithCardRequest(); $request->setCustomerCode('CUST-002'); $request->setFirstName('Bob'); $request->setLastName('Jones'); $request->setGsmNumber('5554443322'); $request->setEmail('bob@example.com'); $request->setCardHolderFullName('Bob Jones'); $request->setCardNumber('4111111111111111'); $request->setExpMonth('06'); $request->setExpYear('2027'); $response = $moka->customers()->createWithCard($request); print_r($response->getData()); ``` -------------------------------- ### cards()->create(), cards()->all(), cards()->retrieve(), cards()->update(), cards()->delete() Source: https://context7.com/optimisthub/moka-php/llms.txt Enables management of tokenized cards associated with customers. ```APIDOC ## `cards()->create()` / `cards()->all()` / `cards()->retrieve()` / `cards()->update()` / `cards()->delete()` — Saved Card Management Manage tokenized cards associated with customers. ### Save a card ```php // Save a card $createCard = new \Moka\Model\CreateCardRequest(); $createCard->setCustomerCode('CUST-001'); $createCard->setCardHolderFullName('Jane Smith'); $createCard->setCardNumber('5127541122223332'); $createCard->setExpMonth('09'); $createCard->setExpYear('2026'); $response = $moka->cards()->create($createCard); $cardToken = $response->getData(); // store for future payments ``` ### List cards for a customer ```php // List cards for a customer $listReq = new \Moka\Model\RetrieveCardListRequest(); $listReq->setCustomerCode('CUST-001'); $cards = $moka->cards()->all($listReq); print_r($cards->getData()); ``` ### Retrieve single card ```php // Retrieve single card $retrieveCard = new \Moka\Model\RetrieveCardRequest(); $retrieveCard->setCustomerCode('CUST-001'); $retrieveCard->setCardToken('TOKEN-XYZ'); $card = $moka->cards()->retrieve($retrieveCard); ``` ### Update card ```php // Update card $updateCard = new \Moka\Model\UpdateCardRequest(); $updateCard->setCustomerCode('CUST-001'); $updateCard->setCardToken('TOKEN-XYZ'); $updateCard->setExpMonth('12'); $updateCard->setExpYear('2028'); $moka->cards()->update($updateCard); ``` ### Delete card ```php // Delete card $deleteCard = new \Moka\Model\DeleteCardRequest(); $deleteCard->setCustomerCode('CUST-001'); $deleteCard->setCardToken('TOKEN-XYZ'); $moka->cards()->delete($deleteCard); ``` ``` -------------------------------- ### customers()->createWithCard() Source: https://context7.com/optimisthub/moka-php/llms.txt Creates a customer and saves a tokenized card in a single API call. This method posts to the /DealerCustomer/AddCustomerWithCard endpoint. ```APIDOC ## `customers()->createWithCard()` — Create Customer with Card Creates a customer and saves a tokenized card in a single API call. Posts to `/DealerCustomer/AddCustomerWithCard`. ### Request Example ```php $request = new \Moka\Model\CreateCustomerWithCardRequest(); $request->setCustomerCode('CUST-002'); $request->setFirstName('Bob'); $request->setLastName('Jones'); $request->setGsmNumber('5554443322'); $request->setEmail('bob@example.com'); $request->setCardHolderFullName('Bob Jones'); $request->setCardNumber('4111111111111111'); $request->setExpMonth('06'); $request->setExpYear('2027'); $response = $moka->customers()->createWithCard($request); print_r($response->getData()); ``` ### Response - **Data** (object) - Contains data related to the created customer and card. ``` -------------------------------- ### Create Customer Record Source: https://context7.com/optimisthub/moka-php/llms.txt Adds a new customer to the dealer's account. Requires customer code, name, phone number, and email. ```php $request = new \Moka\Model\CreateCustomerRequest(); $request->setCustomerCode('CUST-001'); $request->setFirstName('Jane'); $request->setLastName('Smith'); $request->setGsmNumber('5559998877'); $request->setEmail('jane.smith@example.com'); $response = $moka->customers()->create($request); echo $response->getResultCode(); ``` -------------------------------- ### customers()->create() Source: https://context7.com/optimisthub/moka-php/llms.txt Adds a new customer record to the dealer's account. This method posts to the /DealerCustomer/AddCustomer endpoint. ```APIDOC ## `customers()->create()` — Create Customer Adds a new customer record to the dealer's account. Posts to `/DealerCustomer/AddCustomer`. ### Request Example ```php $request = new \Moka\Model\CreateCustomerRequest(); $request->setCustomerCode('CUST-001'); $request->setFirstName('Jane'); $request->setLastName('Smith'); $request->setGsmNumber('5559998877'); $request->setEmail('jane.smith@example.com'); $response = $moka->customers()->create($request); echo $response->getResultCode(); ``` ### Response - **ResultCode** (string) - Indicates the outcome of the customer creation. ``` -------------------------------- ### Create Payment Request Source: https://github.com/optimisthub/moka-php/blob/master/README.md Construct a payment request object by setting all necessary details, including cardholder information, payment amount, currency, and buyer details. This object is then used to initiate a payment. ```php $moka = new \Moka\MokaClient([ 'dealerCode' => 'xxx', 'username' => 'xxx', 'password' => 'xxx', ]); $request = new Moka\Model\CreatePaymentRequest(); $request->setCardHolderFullName('John Doe'); $request->setCardNumber('5555666677778888'); $request->setExpMonth('09'); $request->setExpYear('2024'); $request->setCvcNumber('123'); $request->setAmount(0.01); $request->setCurrency('TL'); $request->setInstallmentNumber(1); $request->setClientIp('192.168.1.116'); $request->setOtherTrxCode('3D5ABC24-456"'); $request->setIsPoolPayment(0); $request->setIsTokenized(0); $request->setIntegratorId(0); $request->setSoftware('Software'); $request->setDescription(''); $request->setIsPreAuth(0); $buyer = new Moka\Model\Buyer(); $buyer->setBuyerFullName('John Doe'); $buyer->setBuyerGsmNumber('5551110022'); $buyer->setBuyerEmail('email@email.com'); $buyer->setBuyerAddress('Levent Mah. Meltem Sok. İş Kuleleri Kule 2 No: 10 / 4 Beşiktaş / İstanbul'); $request->setBuyerInformation($buyer); $payment = $moka->payments()->create($request); $payment->getData(); $payment->getResultCode(); $payment->getResultMessage(); $payment->getException(); ``` -------------------------------- ### refunds()->create() Source: https://context7.com/optimisthub/moka-php/llms.txt Initiates a refund request for a completed payment. This method posts to the /PaymentDealer/DoCreateRefundRequest endpoint. ```APIDOC ## `refunds()->create()` — Create Refund Initiates a refund request for a completed payment. Posts to `/PaymentDealer/DoCreateRefundRequest`. ### Request Example ```php $request = new \Moka\Model\CreateRefundRequest(); $request->setPaymentId(987654); $request->setRefundAmount(25.00); $response = $moka->refunds()->create($request); if ($response->getResultCode() === 'Success') { echo 'Refund initiated.'; } else { echo 'Refund error: ' . $response->getResultMessage(); } ``` ### Response - **ResultCode** (string) - Indicates the outcome of the refund initiation. - **ResultMessage** (string) - Provides a message detailing the outcome of the refund initiation. ``` -------------------------------- ### Manage Product Catalog Source: https://context7.com/optimisthub/moka-php/llms.txt Facilitates the management of product catalog items. Use `create` to add new products, `all` to list existing products, and `delete` to remove products. Ensure `ProductCode` is correctly set for deletion. ```php // Create product $createProduct = new \Moka\Model\CreateProductRequest(); $createProduct->setProductName('Premium Plan'); $createProduct->setProductCode('PROD-PREMIUM'); $createProduct->setAmount(499.00); $response = $moka->products()->create($createProduct); // List all products $products = $moka->products()->all(); print_r($products->getData()); // Delete product $deleteProduct = new \Moka\Model\DeleteProductRequest(); $deleteProduct->setProductCode('PROD-PREMIUM'); $moka->products()->delete($deleteProduct); ``` -------------------------------- ### Manage Schedule Management Source: https://context7.com/optimisthub/moka-php/llms.txt Allows for the creation, listing, retrieval, and deletion of scheduled payment entries. Use `create` for new schedules, `all` to list existing ones, `retrieve` for a specific schedule, and `delete` to remove. Ensure `ScheduleId` is correctly set for retrieval and deletion. ```php // Create a schedule $createSchedule = new \Moka\Model\CreateScheduleRequest(); $createSchedule->setSaleId(55566); $createSchedule->setScheduledDate('2024-03-01'); $createSchedule->setAmount(100.00); $response = $moka->schedules()->create($createSchedule); // List all schedules $allSchedules = $moka->schedules()->all(); print_r($allSchedules->getData()); // Retrieve a specific schedule $retrieveSchedule = new \Moka\Model\RetrieveScheduleRequest(); $retrieveSchedule->setScheduleId(999); $schedule = $moka->schedules()->retrieve($retrieveSchedule); // Delete schedule $deleteSchedule = new \Moka\Model\DeleteScheduleRequest(); $deleteSchedule->setScheduleId(999); $moka->schedules()->delete($deleteSchedule); ``` -------------------------------- ### paymentLinks()->create() Source: https://context7.com/optimisthub/moka-php/llms.txt Generates a hosted payment page URL for user-initiated payments. Posts to /PaymentUserPos/CreateUserPosPayment. ```APIDOC ## `paymentLinks()->create()` — Create Payment Link Generates a hosted payment page URL for user-initiated payments. Posts to `/PaymentUserPos/CreateUserPosPayment`. ### Description Creates a payment link that can be shared with customers to initiate payments. ### Method POST ### Endpoint `/PaymentUserPos/CreateUserPosPayment` ### Request Body - **amount** (float) - Required - The payment amount. - **currency** (string) - Required - The currency code (e.g., 'TL'). - **otherTrxCode** (string) - Required - A unique transaction code. - **description** (string) - Optional - A description for the payment. ### Request Example ```php $request = new \Moka\Model\CreatePaymentLinkRequest(); $request->setAmount(200.00); $request->setCurrency('TL'); $request->setOtherTrxCode('LINK-' . time()); $request->setDescription('Invoice #INV-2024-001'); $response = $moka->paymentLinks()->create($request); ``` ### Response #### Success Response (200) - **data** (string) - The generated payment URL. - **resultCode** (string) - Indicates the result of the operation ('Success' or 'Error'). #### Response Example ```json { "data": "https://your-payment-gateway.com/pay?id=...", "resultCode": "Success" } ``` ``` -------------------------------- ### Create Direct Payment (Non-3DS) with Moka PHP Client Source: https://context7.com/optimisthub/moka-php/llms.txt Initiates a direct payment without 3D Secure authentication. Ensure all required fields in CreatePaymentRequest and BuyerInformation are populated. Handles success and failure responses. ```php $moka = new Moka\ MokaClient([ 'dealerCode' => 'YOUR_DEALER_CODE', 'username' => 'YOUR_USERNAME', 'password' => 'YOUR_PASSWORD', 'baseUrl' => 'https://service.refmoka.com', ]); $request = new Moka\ Model\ CreatePaymentRequest(); $request->setCardHolderFullName('John Doe'); $request->setCardNumber('5127541122223332'); $request->setExpMonth('12'); $request->setExpYear('2025'); $request->setCvcNumber('123'); $request->setAmount(100.00); $request->setCurrency('TL'); $request->setInstallmentNumber(1); $request->setClientIp('192.168.1.100'); $request->setOtherTrxCode('TRX-' . time()); $request->setIsPoolPayment(0); $request->setIsTokenized(0); $request->setIntegratorId(0); $request->setSoftware('MyShop'); $request->setDescription('Order #1234'); $request->setIsPreAuth(0); $buyer = new Moka\ Model\ Buyer(); $buyer->setBuyerFullName('John Doe'); $buyer->setBuyerGsmNumber('5551110022'); $buyer->setBuyerEmail('john@example.com'); $buyer->setBuyerAddress('123 Main St, Istanbul'); $request->setBuyerInformation($buyer); $response = $moka->payments()->create($request); // Handle response if ($response->getResultCode() === 'Success') { echo 'Payment successful. Data: '; print_r($response->getData()); } else { echo 'Payment failed: ' . $response->getResultMessage(); echo 'Exception: ' . $response->getException(); } ``` -------------------------------- ### customers()->all(), customers()->retrieve(), customers()->update(), customers()->delete() Source: https://context7.com/optimisthub/moka-php/llms.txt Provides full CRUD operations for customer management. ```APIDOC ## `customers()->all()` / `customers()->retrieve()` / `customers()->update()` / `customers()->delete()` — Customer CRUD Full CRUD operations for customer management. ### List all customers ```php // List all customers $allResponse = $moka->customers()->all(); print_r($allResponse->getData()); ``` ### Retrieve a specific customer ```php // Retrieve a specific customer $retrieveReq = new \Moka\Model\RetrieveCustomerRequest(); $retrieveReq->setCustomerCode('CUST-001'); $customer = $moka->customers()->retrieve($retrieveReq); print_r($customer->getData()); ``` ### Update customer ```php // Update customer $updateReq = new \Moka\Model\UpdateCustomerRequest(); $updateReq->setCustomerCode('CUST-001'); $updateReq->setEmail('new.email@example.com'); $moka->customers()->update($updateReq); ``` ### Delete customer ```php // Delete customer $deleteReq = new \Moka\Model\DeleteCustomerRequest(); $deleteReq->setCustomerCode('CUST-001'); $moka->customers()->delete($deleteReq); ``` ``` -------------------------------- ### Create Refund Request Source: https://context7.com/optimisthub/moka-php/llms.txt Initiates a refund for a completed payment. Ensure the payment ID and refund amount are correctly specified. ```php $request = new \Moka\Model\CreateRefundRequest(); $request->setPaymentId(987654); $request->setRefundAmount(25.00); $response = $moka->refunds()->create($request); if ($response->getResultCode() === 'Success') { echo 'Refund initiated.'; } else { echo 'Refund error: ' . $response->getResultMessage(); } ``` -------------------------------- ### payments()->create() — Direct Payment (Non-3DS) Source: https://context7.com/optimisthub/moka-php/llms.txt Charges a card directly without 3D Secure authentication. This method posts to `/PaymentDealer/DoDirectPayment` and returns an `ApiResponse` object containing the transaction result. ```APIDOC ## `payments()->create()` — Direct Payment (Non-3DS) Charges a card directly without 3D Secure authentication. Posts to `/PaymentDealer/DoDirectPayment`. Returns an `ApiResponse` with the transaction result. ```php $moka = new \Moka\MokaClient([ 'dealerCode' => 'YOUR_DEALER_CODE', 'username' => 'YOUR_USERNAME', 'password' => 'YOUR_PASSWORD', 'baseUrl' => 'https://service.refmoka.com', ]); $request = new \Moka\Model\CreatePaymentRequest(); $request->setCardHolderFullName('John Doe'); $request->setCardNumber('5127541122223332'); $request->setExpMonth('12'); $request->setExpYear('2025'); $request->setCvcNumber('123'); $request->setAmount(100.00); $request->setCurrency('TL'); $request->setInstallmentNumber(1); $request->setClientIp('192.168.1.100'); $request->setOtherTrxCode('TRX-' . time()); $request->setIsPoolPayment(0); $request->setIsTokenized(0); $request->setIntegratorId(0); $request->setSoftware('MyShop'); $request->setDescription('Order #1234'); $request->setIsPreAuth(0); $buyer = new \Moka\Model\Buyer(); $buyer->setBuyerFullName('John Doe'); $buyer->setBuyerGsmNumber('5551110022'); $buyer->setBuyerEmail('john@example.com'); $buyer->setBuyerAddress('123 Main St, Istanbul'); $request->setBuyerInformation($buyer); $response = $moka->payments()->create($request); // Handle response if ($response->getResultCode() === 'Success') { echo 'Payment successful. Data: '; print_r($response->getData()); } else { echo 'Payment failed: ' . $response->getResultMessage(); echo 'Exception: ' . $response->getException(); } ``` ``` -------------------------------- ### binNumber()->retrieve() Source: https://context7.com/optimisthub/moka-php/llms.txt Retrieves card/bank information for a given BIN (first 6 digits of a card number). This method posts to the /PaymentDealer/GetBankCardInformation endpoint. ```APIDOC ## `binNumber()->retrieve()` — BIN Lookup Retrieves card/bank information for a given BIN (first 6 digits of a card number). Posts to `/PaymentDealer/GetBankCardInformation`. ### Request Example ```php $request = new \Moka\Model\RetrieveBinNumberRequest(); $request->setBinNumber('453144'); $response = $moka->binNumber()->retrieve($request); if ($response->getResultCode() === 'Success') { $info = $response->getData(); // $info->BankName, $info->CardType, $info->CardAssociation, etc. print_r($info); } ``` ### Response - **ResultCode** (string) - Indicates the outcome of the BIN lookup. - **Data** (object) - Contains card/bank information if the lookup is successful. Fields may include BankName, CardType, CardAssociation, etc. ``` -------------------------------- ### payments()->createThreeds() — 3D Secure Payment Source: https://context7.com/optimisthub/moka-php/llms.txt Initiates a 3D Secure authenticated payment. This method posts to `/PaymentDealer/DoDirectPaymentThreeD` and requires a redirect URL to be set for the bank's 3DS callback. ```APIDOC ## `payments()->createThreeds()` — 3D Secure Payment Initiates a 3DS-authenticated payment. Posts to `/PaymentDealer/DoDirectPaymentThreeD`. Requires `setRedirectUrl()` for the bank's 3DS callback. ```php $request = new \Moka\Model\CreatePaymentRequest(); $request->setCardHolderFullName('John Doe'); $request->setCardNumber('5127541122223332'); $request->setExpMonth('12'); $request->setExpYear('2025'); $request->setCvcNumber('123'); $request->setAmount(50.00); $request->setCurrency('TL'); $request->setInstallmentNumber(1); $request->setClientIp('192.168.1.100'); $request->setOtherTrxCode('3DS-' . time()); $request->setIsPoolPayment(0); $request->setIsTokenized(0); $request->setIntegratorId(0); $request->setSoftware('MyShop'); $request->setDescription('Order #5678'); $request->setIsPreAuth(0); $request->setReturnHash(1); $request->setRedirectUrl('https://myshop.com/payment/callback?trx=3DS-' . time()); $request->setRedirectType(0); $buyer = new \Moka\Model\Buyer(); $buyer->setBuyerFullName('John Doe'); $buyer->setBuyerGsmNumber('5551110022'); $buyer->setBuyerEmail('john@example.com'); $buyer->setBuyerAddress('123 Main St, Istanbul'); $request->setBuyerInformation($buyer); $response = $moka->payments()->createThreeds($request); if ($response->getResultCode() === 'Success') { // Redirect user to the 3DS URL returned in getData() $threeDsUrl = $response->getData(); header('Location: ' . $threeDsUrl); } else { echo 'Error: ' . $response->getResultMessage(); } ``` ``` -------------------------------- ### Manage Sales Records Source: https://context7.com/optimisthub/moka-php/llms.txt Provides functionality to create, list, retrieve, update, and delete sale records. Use `create` for new sales, `all` to list all sales, `retrieve` for a specific sale, `update` to modify, and `delete` to remove. Ensure `SaleId` is correctly set for retrieval, update, and deletion operations. ```php // Create a sale $createSale = new \Moka\Model\CreateSaleRequest(); $createSale->setCustomerCode('CUST-001'); $createSale->setAmount(350.00); $createSale->setCurrency('TL'); $response = $moka->sales()->create($createSale); $saleId = $response->getData(); // List all sales $allSales = $moka->sales()->all(); print_r($allSales->getData()); // Retrieve specific sale $retrieveSale = new \Moka\Model\RetrieveSaleRequest(); $retrieveSale->setSaleId($saleId); $sale = $moka->sales()->retrieve($retrieveSale); // Update sale $updateSale = new \Moka\Model\UpdateSaleRequest(); $updateSale->setSaleId($saleId); $updateSale->setDescription('Updated note'); $moka->sales()->update($updateSale); // Delete sale $deleteSale = new \Moka\Model\DeleteSaleRequest(); $deleteSale->setSaleId($saleId); $moka->sales()->delete($deleteSale); ``` -------------------------------- ### all Source: https://context7.com/optimisthub/moka-php/llms.txt Retrieves a list of payments, allowing filtering by date range or other criteria. This method posts to the /PaymentDealer/GetPaymentList endpoint. ```APIDOC ## `payments()->all()` — List Payments ### Description Retrieves a list of payments filtered by date range or other criteria. ### Method POST ### Endpoint /PaymentDealer/GetPaymentList ### Parameters #### Request Body - **startDate** (string) - Optional - The start date for filtering payments (YYYY-MM-DD format). - **endDate** (string) - Optional - The end date for filtering payments (YYYY-MM-DD format). ### Request Example ```php $request = new \Moka\Model\RetrievePaymentListRequest(); $request->setStartDate('2024-01-01'); $request->setEndDate('2024-01-31'); $response = $moka->payments()->all($request); ``` ### Response #### Success Response (200) - **resultCode** (string) - Indicates the result of the operation ('Success' or an error code). - **data** (array) - An array of payment objects if successful. ``` -------------------------------- ### Retrieve Dealer Information Source: https://context7.com/optimisthub/moka-php/llms.txt Fetches dealer account details and configuration by posting to the /Dealer/GetDealer endpoint. Requires a valid dealer code. ```php $request = new \Moka\Model\RetrieveDealerRequest(); $request->setDealerCode('YOUR_DEALER_CODE'); $response = $moka->dealers()->retrieve($request); print_r($response->getData()); ``` -------------------------------- ### Retrieve Dealer Info Source: https://context7.com/optimisthub/moka-php/llms.txt Fetches dealer account details and configuration by posting to the /Dealer/GetDealer endpoint. ```APIDOC ## `dealers()->retrieve()` — Retrieve Dealer Info ### Description Fetches dealer account details and configuration. ### Method POST ### Endpoint /Dealer/GetDealer ### Request Body - **dealerCode** (string) - Required - The code of the dealer to retrieve. ### Request Example ```php $request = new \Moka\Model\RetrieveDealerRequest(); $request->setDealerCode('YOUR_DEALER_CODE'); $response = $moka->dealers()->retrieve($request); ``` ### Response #### Success Response (200) - **data** (object) - The dealer information. ### Response Example ```json { "data": { ... } } ``` ``` -------------------------------- ### Create 3D Secure Payment with Moka PHP Client Source: https://context7.com/optimisthub/moka-php/llms.txt Initiates a 3D Secure payment, requiring a redirect URL for the bank's callback. Ensure the CreatePaymentRequest includes necessary fields and a valid redirectUrl. Handles redirection or error messages. ```php $request = new Moka\ Model\ CreatePaymentRequest(); $request->setCardHolderFullName('John Doe'); $request->setCardNumber('5127541122223332'); $request->setExpMonth('12'); $request->setExpYear('2025'); $request->setCvcNumber('123'); $request->setAmount(50.00); $request->setCurrency('TL'); $request->setInstallmentNumber(1); $request->setClientIp('192.168.1.100'); $request->setOtherTrxCode('3DS-' . time()); $request->setIsPoolPayment(0); $request->setIsTokenized(0); $request->setIntegratorId(0); $request->setSoftware('MyShop'); $request->setDescription('Order #5678'); $request->setIsPreAuth(0); $request->setReturnHash(1); $request->setRedirectUrl('https://myshop.com/payment/callback?trx=3DS-' . time()); $request->setRedirectType(0); $buyer = new Moka\ Model\ Buyer(); $buyer->setBuyerFullName('John Doe'); $buyer->setBuyerGsmNumber('5551110022'); $buyer->setBuyerEmail('john@example.com'); $buyer->setBuyerAddress('123 Main St, Istanbul'); $request->setBuyerInformation($buyer); $response = $moka->payments()->createThreeds($request); if ($response->getResultCode() === 'Success') { // Redirect user to the 3DS URL returned in getData() $threeDsUrl = $response->getData(); header('Location: ' . $threeDsUrl); } else { echo 'Error: ' . $response->getResultMessage(); } ``` -------------------------------- ### Create Payment Link Source: https://context7.com/optimisthub/moka-php/llms.txt Generates a hosted payment page URL for user-initiated payments. Ensure the `CreatePaymentLinkRequest` object is populated with amount, currency, and other relevant details. ```php $request = new \Moka\Model\CreatePaymentLinkRequest(); $request->setAmount(200.00); $request->setCurrency('TL'); $request->setOtherTrxCode('LINK-' . time()); $request->setDescription('Invoice #INV-2024-001'); $response = $moka->paymentLinks()->create($request); if ($response->getResultCode() === 'Success') { $paymentUrl = $response->getData(); echo 'Send this URL to the customer: ' . $paymentUrl; } ``` -------------------------------- ### Retrieve BIN Information Source: https://context7.com/optimisthub/moka-php/llms.txt Retrieves card or bank information using the first 6 digits of a card number (BIN). The response contains details like BankName, CardType, and CardAssociation. ```php $request = new \Moka\Model\RetrieveBinNumberRequest(); $request->setBinNumber('453144'); $response = $moka->binNumber()->retrieve($request); if ($response->getResultCode() === 'Success') { $info = $response->getData(); // $info->BankName, $info->CardType, $info->CardAssociation, etc. print_r($info); } ```