### Install SDK via Git Clone Source: https://github.com/globalpayments/php-sdk/blob/master/README.md Clone the SDK repository directly from GitHub if you prefer not to use Composer. ```bash git clone https://github.com/globalpayments/php-sdk ``` -------------------------------- ### Install SDK via Composer Source: https://github.com/globalpayments/php-sdk/blob/master/README.md Use Composer to add the GlobalPayments PHP SDK to your project. This is the recommended installation method. ```bash composer require globalpayments/php-sdk ``` -------------------------------- ### PIA Testing Example Source: https://github.com/globalpayments/php-sdk/blob/master/test/Integration/Gateways/Terminals/UPA/samples/UDDataFile.html This snippet demonstrates how to stringify a JSON object for a command result and display it on screen during PIA testing. ```javascript var dataStr = JSON.stringify({ 'cmdResult': { 'result':'Success' } }); display.onScreenResult(dataStr); ``` -------------------------------- ### Process a Payment with Credit Card Source: https://github.com/globalpayments/php-sdk/blob/master/README.md Example of processing a payment using credit card details. Ensure you handle potential API exceptions. ```csharp $card = new CreditCardData(); $card->number = "4111111111111111"; $card->expMonth = "12"; $card->expYear = "2025"; $card->cvn = "123"; try { $response = $card->charge(129.99) ->withCurrency("EUR") ->execute(); $result = $response->responseCode; // 00 == Success $message = $response->responseMessage; // [ test system ] AUTHORISED } catch (ApiException $e) { // handle errors } ``` -------------------------------- ### Get Transaction Details by Order ID with BillPay Source: https://github.com/globalpayments/php-sdk/blob/master/src/Gateways/BillPay/Billpay Documentation.md This example shows how to retrieve transaction details using an order ID. It involves verifying a credit card, calculating convenience fees, executing a charge, and then fetching the transaction summary. ```php CreditCardData $clearTextCredit = new CreditCardData(); $clearTextCredit->number = "4444444444444448"; $clearTextCredit->expMonth = "12"; $clearTextCredit->expYear = "2025"; $clearTextCredit->cvn = "123"; $clearTextCredit->cardHolderName = "Test Tester"; $service = new BillPayService(); $address = new Address(); $address->postalCode = '12345'; $bill = new Bill(); $bill->setAmount("50"); $bill->setIdentifier1("12345"); $response = $clearTextCredit->verify() ->withAddress($address) ->withRequestMultiUseToken(true) ->execute(); $token = $response->token; $fee = $service->calculateConvenienceAmount( $clearTextCredit, $bill->getAmount() ); $paymentMethod = new CreditCardData(); $paymentMethod->token = $token; $paymentMethod->expMonth = $clearTextCredit->expMonth; $paymentMethod->expYear = $clearTextCredit->expYear; $orderID = uniqid(); try{ $paymentMethod ->charge($bill->getAmount()) ->withAddress($address) ->withBill($bill) ->withConvenienceAmount($fee) ->withOrderId($orderID) ->withCurrency('USD') ->execute(); $summary = ReportingService::transactionDetail($orderID)->execute(); var_dump($summary); } catch (ApiException $e) { // handle errors here } ``` -------------------------------- ### Get Token for Credit Card Source: https://github.com/globalpayments/php-sdk/blob/master/src/Gateways/BillPay/Billpay Documentation.md Retrieves a token for a credit card after verifying it with address information. Ensure CreditCardData and Address objects are correctly populated before execution. ```php CreditCardData $clearTextCredit = new CreditCardData(); $clearTextCredit->number = "4444444444444448"; $clearTextCredit->expMonth = "12"; $clearTextCredit->expYear = "2025"; $clearTextCredit->cvn = "123"; $clearTextCredit->cardHolderName = "Test Tester"; $address = new Address(); $address->postalCode = "12345"; try { $response = $this->clearTextCredit->verify() ->withAddress($address) ->withRequestMultiUseToken(true) ->execute(); var_dump($response->token); } catch (ApiException $e) { // handle errors } ``` -------------------------------- ### Get Token Information Source: https://github.com/globalpayments/php-sdk/blob/master/src/Gateways/BillPay/Billpay Documentation.md Retrieves information about a token associated with a credit card charge. This involves charging the bill, obtaining a token, and then requesting token information using the credit card object. ```php $clearTextCreditVisa = new CreditCardData(); $clearTextCreditVisa->number = "4444444444444448"; $clearTextCreditVisa->expMonth = $now->format('n'); $clearTextCreditVisa->expYear = $now->format('Y'); $clearTextCreditVisa->cvn = "123"; $clearTextCreditVisa->cardHolderName = $cardHolderName; $bill = new Bill(); $bill->setAmount("50"); $bill->setIdentifier1("12345"); $address = new Address(); $address->streetAddress1 = "1234 Test St"; $address->streetAddress2 = "Apt 201"; $address->city = "Auburn"; $address->state = "AL"; $address->country = "US"; $address->postalCode = "12345" $customer = new Customer(); $customer->address = $this->address; $customer->email = "testemailaddress@e-hps.com"; $customer->firstName = "Test"; $customer->lastName = "Tester"; $customer->homePhone = "555-555-4444"; try { $tokenResponseVisa = $clearTextCreditVisa->charge($bill->getAmount()) ->withAddress($address) ->withCustomerData($customer) ->withBill($bill) ->withCurrency("USD") ->withRequestMultiUseToken(true) ->execute(); $clearTextCreditVisa->token = $tokenResponseVisa->token; $tokenInfoResponseVisa = $clearTextCreditVisa->getTokenInformation(); var_dump($tokenInfoResponseVisa); } catch (ApiException $e) { // handle errors } ``` -------------------------------- ### Make QuickPay Blind Payment and Return Token Source: https://github.com/globalpayments/php-sdk/blob/master/src/Gateways/BillPay/Billpay Documentation.md Initiates a blind payment and requests a multi-use token for future transactions. A unique token is required for each initial request. ```php $address = new Address(); $address->postalCode = "36832"; $customer = new Customer(); $customer->address = $address; $bill = new Bill(); $bill->setAmount("350"); $bill->setIdentifier1("12345"); $bill->setBillType("Tax Payments"); $ach = new ECheck(); $ach->accountNumber = "987987987"; $ach->routingNumber = "062000080"; $ach->accountType = AccountType::CHECKING; $ach->checkType = CheckType::PERSONAL; $ach->secCode = SecCode::WEB; $ach->checkHolderName = "Hank Hill"; $ach->bankName = "Regions"; // need to use diff token everytime $ach->token = "[token here]"; try { $result = $ach->charge($bill->getAmount()) ->withCurrency("USD") ->withAddress($address) ->withBill($bill) ->withConvenienceAmount(2.65) ->withCustomerData($customer) ->withRequestMultiUseToken(true) ->withPaymentMethodUsageMode(PaymentMethodUsageMode::SINGLE) ->execute(); var_dump($result); } catch (ApiException $e) { // handle errors } ``` -------------------------------- ### Initialize HPP Lightbox with Capture Options Source: https://github.com/globalpayments/php-sdk/blob/master/examples/gp-ecom/hpp/example.html Use this JavaScript snippet to initialize the HPP lightbox. It captures user selections for address capture, response return, and shipping removal, then sends this data to a backend endpoint to retrieve HPP configuration before initializing the lightbox. ```javascript $(document).ready(function() { $("#payButtonId").click(function() { const data = { captureAddress: document.getElementById("capture_address").checked, notReturnAddress: document.getElementById("not_return_address").checked, removeShipping: document.getElementById("remove_shipping").checked }; console.log(data); $.getJSON("get-json.php", data, function (jsonFromRequestEndpoint) { console.log(jsonFromRequestEndpoint); RealexHpp.setHppUrl("https://pay.sandbox.realexpayments.com/pay"); /* * if running this from localhost, for your response endpoint, * you will need to expose your local server to the outside world * you can use something like ngrok for it then access your local host via * the ngrok link */ RealexHpp.lightbox.init("autoload", "response-endpoint.php", jsonFromRequestEndpoint); }); }); }); ``` -------------------------------- ### MakeQuickPayBlindPaymentReturnToken Source: https://github.com/globalpayments/php-sdk/blob/master/src/Gateways/BillPay/Billpay Documentation.md Initiates a QuickPay blind payment and requests a multi-use token for future transactions. ```APIDOC ## MakeQuickPayBlindPaymentReturnToken ### Description Initiates a QuickPay blind payment and requests a multi-use token for future transactions. ### Method Not explicitly defined, but implies an API call. ### Endpoint Not explicitly defined. ### Parameters - **bill**: Bill object containing payment details. - **address**: Address object for the transaction. - **customer**: Customer object with address details. - **convenienceAmount**: Optional convenience fee amount. - **currency**: Currency of the transaction. - **requestMultiUseToken**: Set to `true` to request a multi-use token. - **paymentMethodUsageMode**: Mode for payment method usage. - **token**: A unique token for the payment method. ### Request Example ```php $ach->charge($bill->getAmount()) ->withCurrency("USD") ->withAddress($address) ->withBill($bill) ->withConvenienceAmount(2.65) ->withCustomerData($customer) ->withRequestMultiUseToken(true) ->withPaymentMethodUsageMode(PaymentMethodUsageMode::SINGLE) ->execute(); ``` ### Response - **Result**: Details of the executed transaction, potentially including a token. ``` -------------------------------- ### Get Google Transaction Information Source: https://github.com/globalpayments/php-sdk/blob/master/examples/portico/google-pay/index.html Provides Google Pay API with essential transaction details like country, currency, and total price status. Used in payment requests. ```javascript /** * Provide Google Pay API with a payment amount, currency, and amount status * * @see {@link https://developers.google.com/pay/api/web/reference/request-objects#TransactionInfo|TransactionInfo} * @returns {object} transaction info, suitable for use as transactionInfo property of PaymentDataRequest */ function getGoogleTransactionInfo() { return { countryCode: 'US', currencyCode: 'USD', totalPriceStatus: 'FINAL', // set to cart total totalPrice: '1.00' }; } ``` -------------------------------- ### Initialize Google Pay and Request Payment Source: https://github.com/globalpayments/php-sdk/blob/master/examples/portico/google-pay/index.html Initiates the Google Pay payment flow by checking if the user is ready to pay and then displaying the Google Pay button. Prefetches payment data for performance. ```javascript function readyToPayRequest() { const request = { apiVersion: 2, apiVersionMinor: 0, allowedPaymentMethods: [ { type: 'CARD', parameters: { allowedAuthMethods: ['PAN_ONLY', 'CRYPTOGRAM_3DS'], allowedCardNetworks: [ 'AMEX', 'DISCOVER', 'INTERAC', 'JCB', 'MASTERCARD', 'VISA' ], billingAddressRequired: true } } ], transactionInfo: { countryCode: 'US', currencyCode: 'USD', totalPriceStatus: 'FINAL', totalPrice: '1.00' } }; return request; } function getGooglePaymentsClient() { if (googlePayClient) { return googlePayClient; } googlePayClient = new google.payments.api.PaymentsClient({ environment: 'TEST' }); return googlePayClient; } function Payment() { const paymentsClient = getGooglePaymentsClient(); paymentsClient.isReadyToPay(readyToPayRequest()) .then(function (response) { if (response.result) { addGooglePayButton(); // @todo prefetch payment data to improve performance after confirming site functionality // prefetchGooglePaymentData(); } }) .catch(function (err) { // show error in developer console for debugging console.error(err); }); } ``` -------------------------------- ### Configure and Initialize Credit Card Form Source: https://github.com/globalpayments/php-sdk/blob/master/examples/portico/end-to-end/index.html Configure GlobalPayments with your public API key and initialize the credit card form. This sets up event handlers for form readiness, token success, and token errors. ```javascript // Configure account GlobalPayments.configure({ publicApiKey: "pkapi_cert_jKc1FtuyAydZhZfbB3" //gitleaks:allow }); // Create Form const cardForm = GlobalPayments.creditCard.form("#credit-card"); // form-level event handlers. examples: cardForm.ready(() => { console.log("Registration of all credit card fields occurred"); }); cardForm.on("token-success", (resp) => { // add payment token to form as a hidden input const token = document.createElement("input"); token.type = "hidden"; token.name = "payment-reference"; token.value = resp.paymentReference; document.querySelector("input[name=token_value]").value = token.value; document.getElementById('payment_form').submit(); }); cardForm.on("token-error", (resp) => { // show error to the consumer }); // field-level event handlers. example: cardForm.on("card-number", "register", () => { console.log("Registration of Card Number occurred"); }); ``` -------------------------------- ### Configure BillPay Service Source: https://github.com/globalpayments/php-sdk/blob/master/src/Gateways/BillPay/Billpay Documentation.md Set up the BillPayConfig with merchant credentials and service URL. Uncomment the logger lines to enable request logging. ```php $config = new BillPayConfig(); $config->setMerchantName("Dev_Exp_Team_Merchant"); $config->setUsername("user_name"); $config->setPassword("password"); $config->serviceUrl = ServiceEndpoints::BILLPAY_CERTIFICATION; // BILLPAY_PRODUCTION // Uncomment if you want to implement logger //$config->requestLogger = new SampleRequestLogger(new Logger("billpay-logs")); return $config; ``` -------------------------------- ### Create Single Sign-On Account Source: https://github.com/globalpayments/php-sdk/blob/master/src/Gateways/BillPay/Billpay Documentation.md Creates a new customer account for single sign-on purposes. Ensure the Customer object is properly instantiated with required details before calling create(). ```php try { $customer = new Customer(); $customer->firstName = "Integration"; $customer->lastName = "Customer"; $customer->email = "test.test@test.com"; $customer->id = uniqid(); $customer->create(); var_dump($customer); } catch (ApiException $e) { // handle errors } ``` -------------------------------- ### Make Payment Source: https://github.com/globalpayments/php-sdk/blob/master/src/Gateways/BillPay/Billpay Documentation.md Executes a payment transaction, similar to a blind payment, but requires `setUseBillRecordLookup(true)` to be enabled in the configuration. Calculates convenience fees before execution. Requires `CreditCardData`, `Bill`, and `Address` objects. ```php /// add to config /// $config->setUseBillRecordLookup(true); CreditCardData $clearTextCredit = new CreditCardData(); $clearTextCredit->number = "4444444444444448"; $clearTextCredit->expMonth = "12"; $clearTextCredit->expYear = "2025"; $clearTextCredit->cvn = "123"; $clearTextCredit->cardHolderName = "Test Tester"; Bill $bill = new Bill(); $bill->setAmount("50"); $bill->setIdentifier1("12345"); try { $service = new BillPayService(); $fee = $service->calculateConvenienceAmount($clearTextCredit, $bill->getAmount()); $result = $clearTextCredit->charge($bill->getAmount()) ->withAddress($this->address) ->withBill($this->bill) ->withConvenienceAmount($fee) ->withCurrency("USD") ->execute(); var_dump($result) // returns `Transaction` } catch (ApiException $e) { // handle errors } ``` -------------------------------- ### CreateRecurringPayment Source: https://github.com/globalpayments/php-sdk/blob/master/src/Gateways/BillPay/Billpay Documentation.md This snippet demonstrates how to create a recurring payment. It involves setting up credit card details, customer information, and schedule details for the recurring transaction. ```APIDOC ## CreateRecurringPayment This method allows for the creation of a recurring payment schedule. It requires detailed information about the customer, payment method, and the recurring schedule itself. ### Method ```php // Example usage within a try-catch block try { // Credit Card Details CreditCardData $clearTextCredit = new CreditCardData(); $clearTextCredit->number = "4444444444444448"; $clearTextCredit->expMonth = "12"; $clearTextCredit->expYear = "2025"; $clearTextCredit->cvn = "123"; $clearTextCredit->cardHolderName = "Test Tester"; // Customer Address $address = new Address(); $address->streetAddress1 = "1234 Test St"; $address->streetAddress2 = "Apt 201"; $address->city = "Auburn"; $address->state = "AL"; $address->country = "US"; $address->postalCode = "12345"; // Customer Information $customer = new Customer(); $customer->firstName = "Account"; $customer->lastName = "Update"; $customer->email = "account.update@test.com"; $customer->id = uniqid(); $customer->create(); // Bill Details $blindBill = new Bill(); $blindBill->setAmount("50"); $blindBill->setBillType("Tax Payments"); $blindBill->setIdentifier1("12345"); $blindBill->setIdentifier2("23456"); $blindBill->setBillPresentment(BillPresentment::FULL); $blindBill->setDueDate(new DateTime('now')); $blindBill->setCustomer($customer); // Add Payment Method and Create Recurring Schedule /** @var RecurringPaymentMethod */ $paymentMethod = $customer ->addPaymentMethod(uniqid(), $clearTextCredit) ->create(); $customer->address = $address; /** Schedule */ $recur = $paymentMethod->addSchedule(uniqid()) ->withAmount(50.0) ->withBill($blindBill) ->withCustomer($customer) ->withStartDate(new \DateTime()) ->withEndDate(\DateTime::createFromFormat('Y-m-d', '2026-12-21')) ->withnumberOfPaymentsRemaining(27) ->withFrequency(ScheduleFrequency::MONTHLY) ->withToken($paymentMethod->token) ->withPrimaryConvenienceAmount(5.0) ->withLastPrimaryConvenienceAmount(4.0) ->withRecurringAuthorizationType(RecurringAuthorizationType::UNASSIGNED) ->withInitialPaymentMethod(InitialPaymentMethod::CARD) ->create(); var_dump($recur); } catch (ApiException $e) { // Handle API exceptions // echo "API Error: " . $e->getMessage(); } ``` -------------------------------- ### MakeQuickPayBlindPayment Source: https://github.com/globalpayments/php-sdk/blob/master/src/Gateways/BillPay/Billpay Documentation.md Initiates a QuickPay blind payment transaction. This method is used for direct payments without pre-tokenization. ```APIDOC ## MakeQuickPayBlindPayment ### Description Initiates a QuickPay blind payment transaction using ECheck details. ### Method Not explicitly defined, but implies an API call. ### Endpoint Not explicitly defined. ### Parameters - **bill**: Bill object containing payment details like amount, identifier, and type. - **address**: Address object for the transaction. - **customer**: Customer object with address details. - **convenienceAmount**: Optional convenience fee amount. - **currency**: Currency of the transaction (e.g., "USD"). - **paymentMethodUsageMode**: Mode for payment method usage (e.g., SINGLE). - **token**: A unique token for the payment method (needs to be different every time). ### Request Example ```php $ach->charge($bill->getAmount()) ->withAddress($address) ->withCustomerData($customer) ->withBill($bill) ->withConvenienceAmount(2.65) ->withCurrency("USD") ->withPaymentMethodUsageMode(PaymentMethodUsageMode::SINGLE) ->execute(); ``` ### Response - **Transaction**: Details of the executed transaction. ``` -------------------------------- ### CreateSingleSignOnAccount Source: https://github.com/globalpayments/php-sdk/blob/master/src/Gateways/BillPay/Billpay Documentation.md Creates a new single sign-on account for a customer. ```APIDOC ## CreateSingleSignOnAccount ### Description Creates a new single sign-on account for a customer. ### Method Not specified (likely a POST or PUT operation on a customer resource) ### Endpoint Not specified ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body Requires a `Customer` object with `firstName`, `lastName`, `email`, and `id`. ### Request Example ```php try { $customer = new Customer(); $customer->firstName = "Integration"; $customer->lastName = "Customer"; $customer->email = "test.test@test.com"; $customer->id = uniqid(); $customer->create(); var_dump($customer); } catch (ApiException $e) { // handle errors } ``` ### Response #### Success Response Returns the created `Customer` object. #### Response Example ```json { "example": "Customer object details" } ``` ``` -------------------------------- ### Create Recurring Payment with BillPay Source: https://github.com/globalpayments/php-sdk/blob/master/src/Gateways/BillPay/Billpay Documentation.md Use this to set up recurring payments. Ensure all customer, address, and bill details are correctly populated before creating the schedule. ```php try { CreditCardData $clearTextCredit = new CreditCardData(); $clearTextCredit->number = "4444444444444448"; $clearTextCredit->expMonth = "12"; $clearTextCredit->expYear = "2025"; $clearTextCredit->cvn = "123"; $clearTextCredit->cardHolderName = "Test Tester"; $address = new Address(); $address->streetAddress1 = "1234 Test St"; $address->streetAddress2 = "Apt 201"; $address->city = "Auburn"; $address->state = "AL"; $address->country = "US"; $address->postalCode = "12345"; $customer = new Customer(); $customer->firstName = "Account"; $customer->lastName = "Update"; $customer->email = "account.update@test.com"; $customer->id = uniqid(); $customer->create(); $blindBill = new Bill(); $blindBill->setAmount("50"); $blindBill->setBillType("Tax Payments"); $blindBill->setIdentifier1("12345"); $blindBill->setIdentifier2("23456"); $blindBill->setBillPresentment(BillPresentment::FULL); $blindBill->setDueDate(new DateTime('now')); $blindBill->setCustomer($customer); /** @var RecurringPaymentMethod */ $paymentMethod = $customer ->addPaymentMethod(uniqid(), $clearTextCredit) ->create(); $customer->address = $address; /** Schedule */ $recur = $paymentMethod->addSchedule(uniqid()) ->withAmount(50.0) ->withBill($blindBill) ->withCustomer($customer) ->withStartDate(new DateTime()) ->withEndDate( DateTime::createFromFormat('Y-m-d', '2026-12-21')) ->withnumberOfPaymentsRemaining(27) ->withFrequency(ScheduleFrequency::MONTHLY) ->withToken($paymentMethod->token) ->withPrimaryConvenienceAmount(5.0) ->withLastPrimaryConvenienceAmount(4.0) ->withRecurringAuthorizationType(RecurringAuthorizationType::UNASSIGNED) ->withInitialPaymentMethod(InitialPaymentMethod::CARD) ->create(); var_dump($recur); } catch (ApiException $e) { // handle errors } ``` -------------------------------- ### Make QuickPay Blind Payment Source: https://github.com/globalpayments/php-sdk/blob/master/src/Gateways/BillPay/Billpay Documentation.md Initiates a blind payment using the ECheck method. Ensure a unique token is used for each transaction. ```php $address = new Address(); $address->postalCode = "36832"; $customer = new Customer(); $customer->address = $address; $bill = new Bill(); $bill->setAmount("350"); $bill->setIdentifier1("12345"); $bill->setBillType("Tax Payments"); $ach = new ECheck(); $ach->accountNumber = "987987987"; $ach->routingNumber = "062000080"; $ach->accountType = AccountType::CHECKING; $ach->checkType = CheckType::PERSONAL; $ach->secCode = SecCode::WEB; $ach->checkHolderName = "Hank Hill"; $ach->bankName = "Regions"; // need to use diff token everytime $ach->token = "[token here]"; try { /** @var Transaction */ $result = $ach->charge($bill->getAmount()) ->withAddress($address) ->withCustomerData($customer) ->withBill($bill) ->withConvenienceAmount(2.65) ->withCurrency("USD") ->withPaymentMethodUsageMode(PaymentMethodUsageMode::SINGLE) ->execute(); var_dump($result); } catch (ApiException $e) { // handle errors } ``` -------------------------------- ### Update Customer Account with Payment Method Source: https://github.com/globalpayments/php-sdk/blob/master/src/Gateways/BillPay/Billpay Documentation.md Creates a customer, adds a credit card as a payment method, and updates its expiration year. Ensure to handle ApiException. ```php $clearTextCredit = new CreditCardData(); $clearTextCredit->number = "4444444444444448"; $clearTextCredit->expMonth = "12"; $clearTextCredit->expYear = "2025"; $clearTextCredit->cvn = "123"; $clearTextCredit->cardHolderName = "Test Tester"; try { $customer = new Customer(); $customer->firstName = "Account"; $customer->lastName = "Update"; $customer->email = "account.update@test.com"; $customer->id = uniqid(); $customer->create(); /** @var RecurringPaymentMethod */ $paymentMethod = $customer ->addPaymentMethod(uniqid(), $clearTextCredit) ->create(); /** @var CreditCardData */ $creditCardData = $paymentMethod->paymentMethod; $creditCardData->expYear = 2026; $paymentMethod->saveChanges(); } catch (ApiException $e) { // handle errors } ``` -------------------------------- ### Make Payment and Return Token Source: https://github.com/globalpayments/php-sdk/blob/master/src/Gateways/BillPay/Billpay Documentation.md Processes a payment and generates a multi-use token, contingent on `setUseBillRecordLookup(true)` in the configuration. Requires `CreditCardData`, `Address`, `Customer`, and `Bill` objects. Ensure `$now` and `$cardHolderName` are defined. ```php /// add to config /// $config->setUseBillRecordLookup(true); $clearTextCreditVisa = new CreditCardData(); $clearTextCreditVisa->number = "4444444444444448"; $clearTextCreditVisa->expMonth = $now->format('n'); $clearTextCreditVisa->expYear = $now->format('Y'); $clearTextCreditVisa->cvn = "123"; $clearTextCreditVisa->cardHolderName = $cardHolderName; $address = new Address(); $address->streetAddress1 = "1234 Test St"; $address->streetAddress2 = "Apt 201"; $address->city = "Auburn"; $address->state = "AL"; $address->country = "US"; $address->postalCode = "12345" $customer = new Customer(); $customer->address = $this->address; $customer->email = "testemailaddress@e-hps.com"; $customer->firstName = "Test"; $customer->lastName = "Tester"; $customer->homePhone = "555-555-4444"; $bill = new Bill(); $bill->setAmount("50"); $bill->setIdentifier1("12345"); try { $tokenResponseVisa = $clearTextCreditVisa->charge($bill->getAmount()) ->withAddress($address) ->withCustomerData($customer) ->withBill($bill) ->withCurrency("USD") ->withRequestMultiUseToken(true) ->execute(); var_dump($result) // returns `Transaction` } catch (ApiException $e) { // handle errors } ``` -------------------------------- ### Initialize Google Payments Client Source: https://github.com/globalpayments/php-sdk/blob/master/examples/portico/google-pay/index.html Initializes the Google PaymentsClient, which is used to interact with the Google Pay API. It should be called after the Google-hosted JavaScript has loaded. ```javascript let paymentsClient = null; function getGooglePaymentsClient() { if (paymentsClient === null) { paymentsClient = new google.payments.api.PaymentsClient({environment: myConfig.environment}); } return paymentsClient; } ``` -------------------------------- ### Make Blind Payment and Return Token Source: https://github.com/globalpayments/php-sdk/blob/master/src/Gateways/BillPay/Billpay Documentation.md Performs a blind payment and requests a multi-use token for future transactions. Requires `CreditCardData`, `Address`, `Customer`, and `Bill` objects. Ensure `$now` and `$cardHolderName` are defined. ```php $clearTextCreditVisa = new CreditCardData(); $clearTextCreditVisa->number = "4444444444444448"; $clearTextCreditVisa->expMonth = $now->format('n'); $clearTextCreditVisa->expYear = $now->format('Y'); $clearTextCreditVisa->cvn = "123"; $clearTextCreditVisa->cardHolderName = $cardHolderName; $address = new Address(); $address->streetAddress1 = "1234 Test St"; $address->streetAddress2 = "Apt 201"; $address->city = "Auburn"; $address->state = "AL"; $address->country = "US"; $address->postalCode = "12345" $customer = new Customer(); $customer->address = $this->address; $customer->email = "testemailaddress@e-hps.com"; $customer->firstName = "Test"; $customer->lastName = "Tester"; $customer->homePhone = "555-555-4444"; $bill = new Bill(); $bill->setAmount("50"); $bill->setIdentifier1("12345"); try { $tokenResponseVisa = $clearTextCreditVisa->charge($bill->getAmount()) ->withAddress($address) ->withCustomerData($customer) ->withBill($bill) ->withCurrency("USD") ->withRequestMultiUseToken(true) ->execute(); var_dump($result) // returns `Transaction` } catch (ApiException $e) { // handle errors } ``` -------------------------------- ### Save Customer Account Source: https://github.com/globalpayments/php-sdk/blob/master/src/Gateways/BillPay/Billpay Documentation.md Creates a new customer and adds a payment method to their account. A unique ID should be generated for the customer and payment method. ```php try { $customer = new Customer(); $customer->firstName = "Integration"; $customer->lastName = "Customer"; $customer->email = "test.test@test.com"; $customer->id = uniqid(); $customer->create(); /** @var RecurringPaymentMethod */ $paymentMethod = $this->customer ->addPaymentMethod(uniqid(), $this->clearTextCredit) ->create(); var_dump($paymentMethod); } catch (ApiException $e) { // handle errors } ``` -------------------------------- ### Make Blind Payment Source: https://github.com/globalpayments/php-sdk/blob/master/src/Gateways/BillPay/Billpay Documentation.md Initiates a blind payment transaction using credit card details and bill information. Calculates convenience fees before executing the charge. Requires `CreditCardData`, `Bill`, and `Address` objects. ```php CreditCardData $clearTextCredit = new CreditCardData(); $clearTextCredit->number = "4444444444444448"; $clearTextCredit->expMonth = "12"; $clearTextCredit->expYear = "2025"; $clearTextCredit->cvn = "123"; $clearTextCredit->cardHolderName = "Test Tester"; Bill $bill = new Bill(); $bill->setAmount("50"); $bill->setIdentifier1("12345"); try { $service = new BillPayService(); $fee = $service->calculateConvenienceAmount($clearTextCredit, $bill->getAmount()); $result = $clearTextCredit->charge($bill->getAmount()) ->withAddress($this->address) ->withBill($this->bill) ->withConvenienceAmount($fee) ->withCurrency("USD") ->execute(); var_dump($result) // returns `Transaction` } catch (ApiException $e) { // handle errors } ``` -------------------------------- ### Handle Various API Exceptions Source: https://github.com/globalpayments/php-sdk/blob/master/README.md Demonstrates comprehensive error handling for different exception types that can occur during payment processing. Catch specific exceptions for granular error management. ```php try { $response = $card->charge(129.99) ->withCurrency("EUR") ->execute(); } catch (BuilderException $e) { // handle builder errors } catch (ConfigurationException $e) { // handle errors related to your services configuration } catch (GatewayException $e) { // handle gateway errors/exceptions } catch (UnsupportedTransactionException $e) { // handle errors when the configured gateway doesn't support // desired transaction } catch (ApiException $e) { // handle all other errors } ``` -------------------------------- ### MakeBlindPaymentReturnToken Source: https://github.com/globalpayments/php-sdk/blob/master/src/Gateways/BillPay/Billpay Documentation.md Initiates a blind payment transaction and returns a token for future use. This method includes customer data and address information. ```APIDOC ## MakeBlindPaymentReturnToken ### Description Initiates a blind payment transaction and returns a token for future use. This method includes customer data and address information. ### Method POST (Implied by charge operation) ### Endpoint Not explicitly defined, but likely a BillPay service endpoint. ### Parameters #### Request Body (Implied) - **creditCardData** (CreditCardData) - Object containing credit card details (number, expiry, CVN, cardholder name). - **address** (Address) - Customer's address. - **customer** (Customer) - Customer's personal and contact information. - **bill** (Bill) - Object containing bill details (amount, identifier1). - **currency** (string) - Transaction currency (e.g., "USD"). - **requestMultiUseToken** (boolean) - Flag to request a multi-use token. ### Request Example ```php $clearTextCreditVisa = new CreditCardData(); $clearTextCreditVisa->number = "4444444444444448"; $clearTextCreditVisa->expMonth = $now->format('n'); $clearTextCreditVisa->expYear = $now->format('Y'); $clearTextCreditVisa->cvn = "123"; $clearTextCreditVisa->cardHolderName = $cardHolderName; $address = new Address(); $address->streetAddress1 = "1234 Test St"; $address->streetAddress2 = "Apt 201"; $address->city = "Auburn"; $address->state = "AL"; $address->country = "US"; $address->postalCode = "12345" $customer = new Customer(); $customer->address = $this->address; $customer->email = "testemailaddress@e-hps.com"; $customer->firstName = "Test"; $customer->lastName = "Tester"; $customer->homePhone = "555-555-4444"; $bill = new Bill(); $bill->setAmount("50"); $bill->setIdentifier1("12345"); $tokenResponseVisa = $clearTextCreditVisa->charge($bill->getAmount()) ->withAddress($address) ->withCustomerData($customer) ->withBill($bill) ->withCurrency("USD") ->withRequestMultiUseToken(true) ->execute(); ``` ### Response #### Success Response (200) - **Transaction** (object) - Details of the completed transaction, potentially including token information. ``` -------------------------------- ### GetToken Source: https://github.com/globalpayments/php-sdk/blob/master/src/Gateways/BillPay/Billpay Documentation.md Verifies credit card details and generates a token for future use. ```APIDOC ## GetToken ### Description Verifies credit card details and generates a token, optionally allowing for multi-use tokens. ### Method Not specified (likely a POST operation for tokenization) ### Endpoint Not specified ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body Requires `CreditCardData` including `number`, `expMonth`, `expYear`, `cvn`, and `cardHolderName`. An `Address` object with `postalCode` is also required. The `withRequestMultiUseToken(true)` option enables multi-use tokens. ### Request Example ```php CreditCardData $clearTextCredit = new CreditCardData(); $clearTextCredit->number = "4444444444444448"; $clearTextCredit->expMonth = "12"; $clearTextCredit->expYear = "2025"; $clearTextCredit->cvn = "123"; $clearTextCredit->cardHolderName = "Test Tester"; $address = new Address(); $address->postalCode = "12345"; try { $response = $this->clearTextCredit->verify() ->withAddress($address) ->withRequestMultiUseToken(true) ->execute(); var_dump($response->token); } catch (ApiException $e) { // handle errors } ``` ### Response #### Success Response (200) Returns a response object containing the generated `token`. #### Response Example ```json { "token": "generated_token_string" } ``` ``` -------------------------------- ### MakePaymentReturnToken Source: https://github.com/globalpayments/php-sdk/blob/master/src/Gateways/BillPay/Billpay Documentation.md Processes a payment transaction and returns a token for future use. This method also requires `UseBillRecordLookup` to be enabled and includes customer and address details. ```APIDOC ## MakePaymentReturnToken ### Description Processes a payment transaction and returns a token for future use. This method also requires `UseBillRecordLookup` to be enabled and includes customer and address details. ### Method POST (Implied by charge operation) ### Endpoint Not explicitly defined, but likely a BillPay service endpoint. ### Parameters #### Configuration - **UseBillRecordLookup** (boolean) - Set to `true` in `BillPayConfig`. #### Request Body (Implied) - **creditCardData** (CreditCardData) - Object containing credit card details (number, expiry, CVN, cardholder name). - **address** (Address) - Customer's address. - **customer** (Customer) - Customer's personal and contact information. - **bill** (Bill) - Object containing bill details (amount, identifier1). - **currency** (string) - Transaction currency (e.g., "USD"). - **requestMultiUseToken** (boolean) - Flag to request a multi-use token. ### Request Example ```php // Ensure config->setUseBillRecordLookup(true); $clearTextCreditVisa = new CreditCardData(); $clearTextCreditVisa->number = "4444444444444448"; $clearTextCreditVisa->expMonth = $now->format('n'); $clearTextCreditVisa->expYear = $now->format('Y'); $clearTextCreditVisa->cvn = "123"; $clearTextCreditVisa->cardHolderName = $cardHolderName; $address = new Address(); $address->streetAddress1 = "1234 Test St"; $address->streetAddress2 = "Apt 201"; $address->city = "Auburn"; $address->state = "AL"; $address->country = "US"; $address->postalCode = "12345" $customer = new Customer(); $customer->address = $this->address; $customer->email = "testemailaddress@e-hps.com"; $customer->firstName = "Test"; $customer->lastName = "Tester"; $customer->homePhone = "555-555-4444"; $bill = new Bill(); $bill->setAmount("50"); $bill->setIdentifier1("12345"); $tokenResponseVisa = $clearTextCreditVisa->charge($bill->getAmount()) ->withAddress($address) ->withCustomerData($customer) ->withBill($bill) ->withCurrency("USD") ->withRequestMultiUseToken(true) ->execute(); ``` ### Response #### Success Response (200) - **Transaction** (object) - Details of the completed transaction, potentially including token information. ``` -------------------------------- ### MakeBlindPayment Source: https://github.com/globalpayments/php-sdk/blob/master/src/Gateways/BillPay/Billpay Documentation.md Initiates a blind payment transaction using credit card details and bill information. It calculates convenience fees and processes the charge. ```APIDOC ## MakeBlindPayment ### Description Initiates a blind payment transaction using credit card details and bill information. It calculates convenience fees and processes the charge. ### Method POST (Implied by charge operation) ### Endpoint Not explicitly defined, but likely a BillPay service endpoint. ### Parameters #### Request Body (Implied) - **creditCardData** (CreditCardData) - Object containing credit card details (number, expiry, CVN, cardholder name). - **bill** (Bill) - Object containing bill details (amount, identifier1). - **address** (Address) - Customer's address. - **convenienceAmount** (string) - Calculated convenience fee. - **currency** (string) - Transaction currency (e.g., "USD"). ### Request Example ```php $clearTextCredit = new CreditCardData(); $clearTextCredit->number = "4444444444444448"; $clearTextCredit->expMonth = "12"; $clearTextCredit->expYear = "2025"; $clearTextCredit->cvn = "123"; $clearTextCredit->cardHolderName = "Test Tester"; $bill = new Bill(); $bill->setAmount("50"); $bill->setIdentifier1("12345"); $service = new BillPayService(); $fee = $service->calculateConvenienceAmount($clearTextCredit, $bill->getAmount()); $result = $clearTextCredit->charge($bill->getAmount()) ->withAddress($this->address) ->withBill($this->bill) ->withConvenienceAmount($fee) ->withCurrency("USD") ->execute(); ``` ### Response #### Success Response (200) - **Transaction** (object) - Details of the completed transaction. ``` -------------------------------- ### MakePayment Source: https://github.com/globalpayments/php-sdk/blob/master/src/Gateways/BillPay/Billpay Documentation.md Processes a standard payment transaction. This method requires the `UseBillRecordLookup` configuration to be enabled. ```APIDOC ## MakePayment ### Description Processes a standard payment transaction. This method requires the `UseBillRecordLookup` configuration to be enabled. ### Method POST (Implied by charge operation) ### Endpoint Not explicitly defined, but likely a BillPay service endpoint. ### Parameters #### Configuration - **UseBillRecordLookup** (boolean) - Set to `true` in `BillPayConfig`. #### Request Body (Implied) - **creditCardData** (CreditCardData) - Object containing credit card details (number, expiry, CVN, cardholder name). - **bill** (Bill) - Object containing bill details (amount, identifier1). - **address** (Address) - Customer's address. - **convenienceAmount** (string) - Calculated convenience fee. - **currency** (string) - Transaction currency (e.g., "USD"). ### Request Example ```php // Ensure config->setUseBillRecordLookup(true); $clearTextCredit = new CreditCardData(); $clearTextCredit->number = "4444444444444448"; $clearTextCredit->expMonth = "12"; $clearTextCredit->expYear = "2025"; $clearTextCredit->cvn = "123"; $clearTextCredit->cardHolderName = "Test Tester"; $bill = new Bill(); $bill->setAmount("50"); $bill->setIdentifier1("12345"); $service = new BillPayService(); $fee = $service->calculateConvenienceAmount($clearTextCredit, $bill->getAmount()); $result = $clearTextCredit->charge($bill->getAmount()) ->withAddress($this->address) ->withBill($this->bill) ->withConvenienceAmount($fee) ->withCurrency("USD") ->execute(); ``` ### Response #### Success Response (200) - **Transaction** (object) - Details of the completed transaction. ``` -------------------------------- ### Reverse a Payment Transaction Source: https://github.com/globalpayments/php-sdk/blob/master/src/Gateways/BillPay/Billpay Documentation.md Calculates convenience fees, makes an initial charge, and then reverses the transaction. Requires CreditCardData, Bill, Address, and Transaction objects. Ensure to handle potential exceptions. ```php $service = new BillPayService(); CreditCardData $clearTextCredit = new CreditCardData(); $clearTextCredit->number = "4444444444444448"; $clearTextCredit->expMonth = "12"; $clearTextCredit->expYear = "2025"; $clearTextCredit->cvn = "123"; $clearTextCredit->cardHolderName = "Test Tester"; $bill = new Bill(); $bill->setAmount("350"); $bill->setIdentifier1("12345"); $bill->setBillType("Tax Payments"); $fee = $service->calculateConvenienceAmount( $clearTextCredit, $bill->getAmount() ); $address = new Address(); $address->streetAddress1 = "1234 Test St"; $address->streetAddress2 = "Apt 201"; $address->city = "Auburn"; $address->state = "AL"; $address->country = "US"; $address->postalCode = "12345" // Make transaction to reverse $transaction = $this->clearTextCredit->charge($this->bill->getAmount()) ->withAddress($this->address) ->withBill($this->bill) ->withConvenienceAmount($fee) ->withCurrency("USD") ->execute(); // Now reverse it $reversal = new Transaction(); $reversal->transactionId = $transaction->transactionId; $reversal->reverse($bill->getAmount()) ->withConvenienceAmount($fee) ->execute(); ```