{"id":19040152,"url":"https://github.com/logisticinfotech/square-payment-method-in-laravel","last_synced_at":"2025-04-23T21:07:20.681Z","repository":{"id":39404136,"uuid":"204635405","full_name":"logisticinfotech/square-payment-method-in-laravel","owner":"logisticinfotech","description":"square payment method in laravel","archived":false,"fork":false,"pushed_at":"2023-01-04T08:20:00.000Z","size":835,"stargazers_count":4,"open_issues_count":21,"forks_count":4,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-30T03:31:37.487Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/logisticinfotech.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-08-27T06:31:41.000Z","updated_at":"2024-10-07T10:52:45.000Z","dependencies_parsed_at":"2023-02-02T05:01:01.186Z","dependency_job_id":null,"html_url":"https://github.com/logisticinfotech/square-payment-method-in-laravel","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/logisticinfotech%2Fsquare-payment-method-in-laravel","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/logisticinfotech%2Fsquare-payment-method-in-laravel/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/logisticinfotech%2Fsquare-payment-method-in-laravel/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/logisticinfotech%2Fsquare-payment-method-in-laravel/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/logisticinfotech","download_url":"https://codeload.github.com/logisticinfotech/square-payment-method-in-laravel/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249357506,"owners_count":21256793,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-08T22:20:52.334Z","updated_at":"2025-04-17T16:32:30.823Z","avatar_url":"https://github.com/logisticinfotech.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# square-payment-method-in-laravel\nsquare payment method in laravel\n\n## Front End\n\n### Square’s Payment Form\n\nIntegrate SqPaymentForm, while integrating SqPaymentForm you can customize the look and feel of input fields.This form directly take card details from  customer on square server and  the payment form  provides method for getting none or one time card token. SqPaymentForm provide many method, you can know from [here](https://developer.squareup.com/docs/api/paymentform)\n\n**Form Component**\n\nMain point to note is the div element with id's.\n```\n    \u003cdiv id=\"form-container\" class=\"add-card-section\"\u003e\n        \u003cdiv id=\"sq-card-number\"\u003e\u003c/div\u003e\n        \u003cdiv id=\"sq-expiration-date\"\u003e\u003c/div\u003e\n        \u003cdiv id=\"sq-cvv\"\u003e\u003c/div\u003e\n        \u003cdiv id=\"sq-postal-code\"\u003e\u003c/div\u003e\n        \u003cbutton id=\"sq-creditcard\" class=\"button-credit-card\" onclick=\"onGetCardNonce(event)\"\u003ePay $1.00\u003c/button\u003e\n    \u003c/div\u003e\n```\n\n\u003eLoad Form from square script\n\n```\n    \u003cscript src=”https://js.squareup.com/v2/paymentform”\u003e\u003c/script\u003e\n```\n\n\u003eFor sandbox testing\n\n```\n    \u003cscript src=\"https://js.squareupsandbox.com/v2/paymentform\"\u003e\n```\n\n```\n    const paymentForm = new SqPaymentForm({\n        // Initialize the payment form elements\n\n        //Replace with your application ID or sandbox application Id for testing\n        applicationId: \"xxxxxxxxxx\",\n        inputClass: 'sq-input',\n        autoBuild: false,\n        // Customize the CSS for SqPaymentForm iframe elements\n        inputStyles: [{\n            fontSize: '16px',\n            lineHeight: '24px',\n            padding: '16px',\n            placeholderColor: '#a0a0a0',\n            backgroundColor: 'transparent',\n        }],\n        // Initialize the credit card placeholders\n        cardNumber: {\n            elementId: 'sq-card-number',\n            placeholder: 'Card Number'\n        },\n        cvv: {\n            elementId: 'sq-cvv',\n            placeholder: 'CVV'\n        },\n        expirationDate: {\n            elementId: 'sq-expiration-date',\n            placeholder: 'MM/YY'\n        },\n        postalCode: {\n            elementId: 'sq-postal-code',\n            placeholder: 'Postal'\n        },\n        // SqPaymentForm callback functions\n        callbacks: {\n            /*\n            * callback function: cardNonceResponseReceived\n            * Triggered when: SqPaymentForm completes a card nonce request\n            */\n            cardNonceResponseReceived: function (errors, nonce, cardData) {\n            if (errors) {\n              // Log errors from nonce generation to the browser developer console.\n              console.error('Encountered errors:');\n              errors.forEach(function (error) {\n                console.error('  ' + error.message);\n              });\n              alert('Encountered errors, check browser developer console for more details');\n              return;\n            }\n              //TODO: Replace alert with code in step 2.1\n                alert('here is your card token ' + nonce);\n            }\n        }\n      });\n      paymentForm.build();\n\n      // onGetCardNonce is triggered when the \"Pay $1.00\" button is clicked\n      function onGetCardNonce(event) {\n        // Don't submit the form until SqPaymentForm returns with a nonce\n        event.preventDefault();\n        // Request a nonce from the SqPaymentForm object\n        paymentForm.requestCardNonce();\n     }\n```\n\n#Back End\n\nhere we get nonce(card-token), now furthur process we have to use Square Connect PHP SDK.\nFor more information, you can visit [here](https://github.com/square/connect-php-sdk)\nThe PHP SDK is available on Packagist. To add it to Composer, simply run:\n\n```\n    composer require square/connect\n```\n\n\u003enow for configure square you required\n\n```\n    $accessToken = 'xxxxx'; // from square dashboard\n    $locationId = 'xxxxx'; // from square dashboard\n    $defaultApiConfig = new \\SquareConnect\\Configuration();\n\n    //$defaultApiConfig-\u003esetHost(\"https://connect.squareupsandbox.com\"); // for testing in sandbox\n    $defaultApiConfig-\u003esetHost(\"https://connect.squareup.com\");\n\n\n    $defaultApiConfig-\u003esetAccessToken($accessToken);\n    $defaultApiClient = new \\SquareConnect\\ApiClient($defaultApiConfig); //need to pass in all api\n```\n\n**add customer with card at Square server**\n\n```\n        $name = 'xxxxx';\n        $email = 'xxx@gmail.com';\n        $streetAddress ='xxxx';\n\n         $customerAddress = new \\SquareConnect\\Model\\Address();\n        $customerAddress-\u003esetAddressLine1($streetAddress);\n\n        $customer = new \\SquareConnect\\Model\\CreateCustomerRequest();\n        $customer-\u003esetGivenName($name);\n        $customer-\u003esetEmailAddress($email);\n        $customer-\u003esetAddress($customerAddress);\n\n\n        $customersApi = new \\SquareConnect\\Api\\CustomersApi($defaultApiClient);\n        $result = $customersApi-\u003ecreateCustomer($customer);\n        $customerId = $result-\u003egetCustomer()-\u003egetId(); //save this customerId\n\n```\n**now add card with customer**\n\n```\n    $customerId = 'xxxx';\n    $body = new \\SquareConnect\\Model\\CreateCustomerCardRequest();\n    $body-\u003esetCardNonce($cardNonce); // nonce get from SqPaymentForm one time token\n\n    $customersApi = new \\SquareConnect\\Api\\CustomersApi($this-\u003edefaultApiClient);\n    $result = $customersApi-\u003ecreateCustomerCard($customerId, $body);\n\n    $card_id = $result-\u003egetCard()-\u003egetId(); // save this card_id for take payment\n    $card_brand = $result-\u003egetCard()-\u003egetCardBrand();\n    $card_last_four = $result-\u003egetCard()-\u003egetLast4();\n    $card_exp_month = $result-\u003egetCard()-\u003egetExpMonth();\n    $card_exp_year = $result-\u003egetCard()-\u003egetExpYear();\n```\n\n**charge customer**\n\n```\n\n    $payment_body = new \\SquareConnect\\Model\\CreatePaymentRequest();\n\n    $amountMoney = new \\SquareConnect\\Model\\Money();\n\n    # Monetary amounts are specified in the smallest unit of the applicable currency.\n    # This amount is in cents. It's also hard-coded for $1.00, which isn't very useful.\n    $amountMoney-\u003esetAmount(100);\n    $amountMoney-\u003esetCurrency(\"USD\");\n    $payment_body-\u003esetCustomerId($customerId);\n    $payment_body-\u003esetSourceId($cardId);\n    $payment_body-\u003esetAmountMoney($amountMoney);\n    $payment_body-\u003esetLocationId($this-\u003elocationId);\n\n    # Every payment you process with the SDK must have a unique idempotency key.\n    # If you're unsure whether a particular payment succeeded, you can reattempt\n    # it with the same idempotency key without worrying about double charging\n    # the buyer.\n    $payment_body-\u003esetIdempotencyKey(uniqid());\n\n    $paymentsApi = new \\SquareConnect\\Api\\PaymentsApi($this-\u003edefaultApiClient);\n    $result = $paymentsApi-\u003ecreatePayment($payment_body);\n    $transactionId = $result-\u003egetPayment()-\u003egetId(); //save this transactionId\n```\n\n**refund customer**\n\n```\n\n    $body = new \\SquareConnect\\Model\\RefundPaymentRequest();\n    $amountMoney = new \\SquareConnect\\Model\\Money();\n\n    # Monetary amounts are specified in the smallest unit of the applicable currency.\n    # This amount is in cents. It's also hard-coded for $1.00, which isn't very useful.\n    $amountMoney-\u003esetAmount(100);\n    $amountMoney-\u003esetCurrency(\"USD\");\n\n    $body-\u003esetPaymentId($paymentId);\n    $body-\u003esetAmountMoney($amountMoney);\n    $body-\u003esetIdempotencyKey(uniqid());\n    $body-\u003esetReason('wrong order');\n\n    $refundApi = new \\SquareConnect\\Api\\RefundsApi($this-\u003edefaultApiClient);\n    $result = $refundApi-\u003erefundPayment($body);\n```\n\nFrom [here](https://developer.squareup.com/apps),you can test and view sandbox dashboard","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flogisticinfotech%2Fsquare-payment-method-in-laravel","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flogisticinfotech%2Fsquare-payment-method-in-laravel","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flogisticinfotech%2Fsquare-payment-method-in-laravel/lists"}