### AliPay Payment Setup Source: https://github.com/fall1600/newebpay/blob/master/README.md Details on setting up payments via AliPay, including required parameters and product information. ```APIDOC ## AliPay Payment Setup - **$payer**: Your payer object, must implement `AliPayPayerInterface` from the package. - **$numberOfProducts**: The number of items in this order (integer). - **$product1**: The first item (implementing `AliPayProductInterface`). - **$product2**: The second item (implementing `AliPayProductInterface`). ```php $info = new AliPayBasicInfo($merchantId, $notifyUrl, $order, $payer, $numberOfProducts); $info = new EnableAliPay($info); $info = new AliPayProduct($info, 1, $product1); $info = new AliPayProduct($info, 2, $product2); ``` ``` -------------------------------- ### Multi-functional Payment Setup Source: https://github.com/fall1600/newebpay/blob/master/README.md This section covers setting up multi-functional payments, enabling various payment methods like credit cards, installments, barcode payments, Google Pay, and Web ATM. It also includes handling offline payments and setting return/cancel URLs. ```APIDOC ## Create Transaction Information (BasicInfo) - **$merchantId**: Your merchant ID with Newebpay. - **$notifyUrl**: Callback URL to receive Newebpay payment notifications. - **$order**: Your order object, must implement `OrderInterface` from the package. - **$payer**: Your payer object, must implement `PayerInterface` from the package. ```php $info = new BasicInfo($merchantId, $notifyUrl, $order, $payer); ``` ## Enable Payment Methods Enable payment methods as needed. ```php // Enable Credit Card $info = new EnableCredit($info); // Enable 3, 6, 12 installments $info = new PayInInstallments($info, '3,6,12'); // Enable Convenience Store Barcode Payment $info = new EnableBarcode($info); // Enable Google Pay $info = new EnableGooglePay($info); // Enable Web ATM $info = new EnableWebAtm($info); // For non-real-time transactions, set the callback URL for Newebpay to notify payment information and the payment deadline. $info = new OfflinePay($info, $customerUrl, $ttl); // URL to redirect to after payment completion on Newebpay $info = new PayComplete($info, $returnUrl); // Page to redirect to when the customer presses 'back' on the payment page $info = new PayCancel($info, $clientBackUrl); // Refer to the document for a mapping of payment methods. ``` ## Create NewebPay Object and Initiate Checkout - **$merchantId**: Your merchant ID with Newebpay. - **$hashKey**: Your exclusive HashKey with Newebpay. - **$hashIv**: Your exclusive Hash IV with Newebpay. ```php $newebpay = new NewebPay(); $newebpay ->setIsProduction(false) // Set environment, defaults to production ->setMerchant(new Merchant($merchantId, $hashKey, $hashIv)) ->checkout($info); ``` ## Implement OrderInterface ```php setRawData($request->all())->validateResponse(); // Proceed if true // The response object encapsulates the notification transaction results. Common methods include: $response = $merchant->getResponse(); // Payment success or failure $response->getStatus(); // Get transaction serial number $response->getTradeNo(); // Get order number, which is getMerchantOrderNo() from OrderInterface implementation $response->getMerchantOrderNo(); // Payment time $response->getPayTime(); ``` ``` -------------------------------- ### Recurring Credit Card Payment Setup Source: https://github.com/fall1600/newebpay/blob/master/README.md This section details how to set up recurring credit card payments using the Newebpay API. It covers creating transaction information, adding optional URLs, and initializing the NewebPay object with merchant details. ```APIDOC ## Create Transaction Information (BasicInfo) - **$order**: Your order object, must implement `OrderInterface` from the package. - **$contact**: Your contact object, must implement `ContactInterface` from the package. - **$periodStartType**: Checks card number pattern, refer to document p.13. - **$version**: Integration version. - If version 1.0 is used, the [last three digits of the back] will be a required field. - If version 1.1 is used, the [last three digits of the back] will be an optional field. ```php $info = new \fall1600\Package\Newebpay\Info\Period\BasicInfo($order, $payer, $periodStartType, $version); ``` ## Optional Parameters ```php $info = new ReturnUrl($info, 'https://your.return.url'); $info = new NotifyUrl($info, 'https://your.notify.url'); $info = new BackUrl($info, 'https://your.back.url'); $info = new Memo($info, 'your memo here'); ``` ## Create NewebPay Object and Issue Recurring Payment - **$merchantId**: Your merchant ID with Newebpay. - **$hashKey**: Your exclusive HashKey with Newebpay. - **$hashIv**: Your exclusive Hash IV with Newebpay. ```php $newebpay = new NewebPay(); $newebpay ->setIsProduction(false) // Set environment, defaults to production ->setMerchant(new Merchant($merchantId, $hashKey, $hashIv)) ->issue($info); ``` ## Implement OrderInterface ```php '3,6,12' // Open all installment options $info = new PayInInstallments($info, '1'); // Disable installments explicitly $info = new PayInInstallments($info, '0'); ``` -------------------------------- ### NewebPay Constants for Encryption, Language, and Period Types Source: https://context7.com/fall1600/newebpay/llms.txt Use these constants to configure encryption methods, payment page languages, and recurring payment statuses and start behaviors. Ensure correct constants are used for desired functionality. ```php use fall1600\Package\Newebpay\Constants\Cipher; use fall1600\Package\Newebpay\Constants\LanguageType; use fall1600\Package\Newebpay\Constants\Period\AlterType; use fall1600\Package\Newebpay\Constants\Period\PeriodStartType; use fall1600\Package\Newebpay\Constants\Period\VersionType; use fall1600\Package\Newebpay\NewebPay; // Encryption algorithm Cipher::METHOD; // 'AES-256-CBC' // Payment page language LanguageType::ZH_TW; // 'zh-tw' — Traditional Chinese (default) LanguageType::EN; // 'en' — English LanguageType::JP; // 'JP' — Japanese // Recurring mandate status changes AlterType::SUSPEND; // 'suspend' — pause authorisations AlterType::RESTART; // 'restart' — resume paused mandate AlterType::TERMINATE; // 'terminate' — permanently cancel (cannot restart) // Recurring mandate start behaviour PeriodStartType::_1; // '1' — immediately auth NTD 10, then auto-void PeriodStartType::_2; // '2' — immediately auth the full periodic amount PeriodStartType::_3; // '3' — no immediate auth; first auth on schedule // Period API protocol version VersionType::V1_0; // '1.0' — CVV is mandatory VersionType::V1_1; // '1.1' — CVV is optional ``` -------------------------------- ### Enable Payment Methods for Multi-functional Payments Source: https://github.com/fall1600/newebpay/blob/master/README.md Chain objects to enable specific payment methods like credit cards, installments, barcode, Google Pay, or Web ATM. Use OfflinePay for non-real-time transactions and PayComplete/PayCancel for redirect URLs. ```php // 啟用信用卡 $info = new EnableCredit($info); // 啟用3, 6, 12 期分期付款 $info = new PayInInstallments($info, '3,6,12'); // 啟用超商條碼 $info = new EnableBarcode($info); // 啟用Google Pay $info = new EnableGooglePay($info); // 啟用Web ATM $info = new EnableWebAtm($info); // 搭配非即時交易, 設定藍新通知付款資訊的callback url, 以及繳費期限 $info = new OfflinePay($info, $customerUrl, $ttl); // 在藍新交易完成後導回的網址 $info = new PayComplete($info, $returnUrl); // 設定讓消費者在付款頁按下返回時可以回導的頁面 $info = new PayCancel($info, $clientBackUrl); ``` -------------------------------- ### Initialize NewebPay Facade Source: https://context7.com/fall1600/newebpay/llms.txt Sets up the Merchant instance and NewebPay facade. Configure production/sandbox environment and optionally set a custom HTML form ID. ```php use fall1600\Package\Newebpay\NewebPay; use fall1600\Package\Newebpay\Merchant; $merchant = new Merchant('MS123456789', 'hashKey32chars__________________', 'hashIV16chars___'); $newebpay = new NewebPay(); $newebpay ->setIsProduction(false) // true (default) = production; false = sandbox ->setMerchant($merchant) ->setFormId('my-pay-form'); // optional: customise the HTML form's id attribute ``` -------------------------------- ### Configure AliPay Payment with Product Details Source: https://context7.com/fall1600/newebpay/llms.txt Use AliPayBasicInfo as the base for AliPay payments and wrap it with EnableAliPay and AliPayProduct decorators for each product. This requires custom Payer and ProductItem classes implementing specific interfaces. ```php use fall1600\Package\Newebpay\Info\AliPayBasicInfo; use fall1600\Package\Newebpay\Info\Decorator\AliPayProduct; use fall1600\Package\Newebpay\Info\Decorator\EnableAliPay; use fall1600\Package\Newebpay\Contracts\AliPayPayerInterface; use fall1600\Package\Newebpay\Contracts\AliPayProductInterface; class AliPayPayer implements AliPayPayerInterface { public function getEmail(): string { return 'buyer@example.com'; } public function getReceiver(): string { return 'Wang Xiaohua'; } public function getTel1(): string { return '0912345678'; } // primary phone public function getTel2(): string { return '0223456789'; } // secondary phone } class ProductItem implements AliPayProductInterface { public function __construct( private int $id, private string $title, private string $desc, private int $price, private int $qty ) {} public function getProductId(): int { return $this->id; } public function getTitle(): string { return $this->title; } public function getDescription(): string{ return $this->desc; } public function getPrice(): int { return $this->price; } public function getQuantity(): int { return $this->qty; } } $payer = new AliPayPayer(); $prod1 = new ProductItem(1001, 'Widget A', 'Blue widget', 500, 2); $prod2 = new ProductItem(1002, 'Widget B', 'Red widget', 750, 1); $info = new AliPayBasicInfo( 'MS123456789', 'https://yoursite.com/notify', $order, // implements Contracts\OrderInterface $payer, 2 // total number of distinct product types ); $info = new EnableAliPay($info); // adds 'ALIPAY' => 1 $info = new AliPayProduct($info, 1, $prod1); // adds Pid1, Title1, Desc1, Price1, Qty1 $info = new AliPayProduct($info, 2, $prod2); // adds Pid2, Title2, Desc2, Price2, Qty2 ``` -------------------------------- ### Configure AliPay Payment Basic Info Source: https://github.com/fall1600/newebpay/blob/master/README.md Set up the AliPayBasicInfo object for Alipay payments, including payer, product details, and quantity. Ensure the payer implements AliPayPayerInterface and products implement AliPayProductInterface. ```php $info = new AliPayBasicInfo($merchantId, $notifyUrl, $order, $payer, $numberOfProducts); $info = new EnableAliPay($info); $info = new AliPayProduct($info, 1, $product1); $info = new AliPayProduct($info, 2, $product2); ``` -------------------------------- ### Initialize NewebPay for Multi-functional Payments Source: https://github.com/fall1600/newebpay/blob/master/README.md Set up the NewebPay object with merchant credentials and the configured transaction information. Use setIsProduction(false) for testing. ```php $newebpay = new NewebPay(); $newebpay ->setIsProduction(false) // 設定環境, 預設就是走正式機 ->setMerchant(new Merchant($merchantId, $hashKey, $hashIv)) ->checkout($info); ``` -------------------------------- ### Initialize NewebPay for Recurring Payments Source: https://github.com/fall1600/newebpay/blob/master/README.md Set up the NewebPay object with your merchant credentials and the prepared transaction information. Use setIsProduction(false) to test in a non-production environment. ```php $newebpay = new NewebPay(); $newebpay ->setIsProduction(false) // 設定環境, 預設就是走正式機 ->setMerchant(new Merchant($merchantId, $hashKey, $hashIv)) ->issue($info); ``` -------------------------------- ### Implement BasicInfo for NewebPay Transactions Source: https://context7.com/fall1600/newebpay/llms.txt Implement the OrderInterface and PayerInterface in your domain objects. Then, build the BasicInfo object with mandatory fields like MerchantID, NotifyURL, and order/payer details. ```php use fall1600\Package\Newebpay\Info\BasicInfo; use fall1600\Package\Newebpay\Contracts\OrderInterface; use fall1600\Package\Newebpay\Contracts\PayerInterface; // ── 1. Implement the two required interfaces in your domain ── class MyOrder implements OrderInterface { public function __construct( private int $amt, private string $orderNo, private string $itemDesc ) {} public function getAmt(): int { return $this->amt; } public function getMerchantOrderNo(): string { return $this->orderNo; } public function getItemDesc(): string { return $this->itemDesc; } } class MyPayer implements PayerInterface { public function __construct(private string $email) {} public function getEmail(): string { return $this->email; } } // ── 2. Build BasicInfo ── $order = new MyOrder(1500, 'ORD-20240115-001', 'Widget × 3'); $payer = new MyPayer('buyer@example.com'); $info = new BasicInfo( 'MS123456789', // MerchantID 'https://yoursite.com/newebpay/notify', // NotifyURL (server callback) $order, $payer ); // $info->getInfo() produces: // [ // 'MerchantID' => 'MS123456789', // 'RespondType' => 'JSON', // 'TimeStamp' => 1705291800, // 'Version' => '2.3', // 'NotifyURL' => 'https://yoursite.com/newebpay/notify', // 'Amt' => 1500, // 'ItemDesc' => 'Widget × 3', // 'MerchantOrderNo' => 'ORD-20240115-001', // 'Email' => 'buyer@example.com', // ] ``` -------------------------------- ### Set Up Recurring Payments with NewebPay PHP SDK Source: https://context7.com/fall1600/newebpay/llms.txt Use `PeriodBasicInfo` and decorators to configure recurring payments. Ensure `PeriodOrderInterface` and `ContactInterface` are implemented. The `PeriodStartType` constant determines immediate card verification. ```php use fall1600\Package\Newebpay\Info\Period\BasicInfo as PeriodBasicInfo; use fall1600\Package\Newebpay\Info\Period\Decorator\ReturnUrl; use fall1600\Package\Newebpay\Info\Period\Decorator\NotifyUrl; use fall1600\Package\Newebpay\Info\Period\Decorator\BackUrl; use fall1600\Package\Newebpay\Info\Period\Decorator\Memo; use fall1600\Package\Newebpay\Constants\Period\PeriodStartType; use fall1600\Package\Newebpay\Constants\Period\VersionType; use fall1600\Package\Newebpay\Contracts\Period\OrderInterface as PeriodOrderInterface; use fall1600\Package\Newebpay\Contracts\Period\ContactInterface; class SubscriptionOrder implements PeriodOrderInterface { public function getMerOrderNo(): string { return 'SUB-2024-001'; } public function getAmount(): int { return 299; } // TWD per cycle public function getProdDesc(): string { return 'Monthly Premium Plan'; } public function getPeriodType(): string { return 'M'; } // D/W/M/Y public function getPeriodPoint(): string { return '01'; } // 1st of each month public function getPeriodTimes(): string { return '12'; } // 12 billing cycles } class SubscriberContact implements ContactInterface { public function getPayerEmail(): string { return 'sub@example.com'; } public function getPayerEmailModify(): int { return 0; } // 0=locked, 1=editable public function getPaymentInfo(): string { return 'Y'; } // show payment info form public function getOrderInfo(): string { return 'N'; } // hide shipping form } $subOrder = new SubscriptionOrder(); $subscriber = new SubscriberContact(); $info = new PeriodBasicInfo( $subOrder, $subscriber, PeriodStartType::_1, // verify card with NTD 10 auth then auto-void VersionType::V1_1 // CVV non-mandatory ); // Optional URL decorators $info = new ReturnUrl($info, 'https://yoursite.com/subscription/success'); $info = new NotifyUrl($info, 'https://yoursite.com/subscription/notify'); $info = new BackUrl($info, 'https://yoursite.com/subscription/cancel'); $info = new Memo($info, 'Monthly subscription — thank you!'); // Dispatch to NewebPay $newebpay = new \fall1600\Package\Newebpay\NewebPay(); $newebpay ->setIsProduction(false) ->setMerchant(new \fall1600\Package\Newebpay\Merchant('MS123456789', 'key32chars______________________', 'iv_16chars______')) ->issue($info); // echoes self-submitting HTML page ``` -------------------------------- ### NewebPay Facade Methods Source: https://context7.com/fall1600/newebpay/llms.txt This section details the various methods available on the NewebPay facade for different payment scenarios. ```APIDOC ## NewebPay Facade The `NewebPay` facade is the primary entry point for interacting with the NewebPay service. It allows for various payment operations, including generating HTML for redirects, creating form fragments, and handling API-based transactions. ### Methods #### `checkout($info)` **Description**: Outputs a complete self-submitting HTML page for redirecting users to the NewebPay payment gateway. **Method**: POST (implicitly via HTML form submission) **Endpoint**: N/A (generates HTML) **Parameters**: - `$info`: An object containing payment details. **Request Example**: ```php $newebpay->checkout($info); ``` #### `generateForm($info)` **Description**: Returns only the HTML `