{"_rev":"2-2eb7a3b53a8043af1f9691d9737187c8","time":{"created":"2024-04-02T09:30:24.221Z","1.0.0":"2024-04-02T09:06:38.311Z","modified":"2024-04-02T09:30:24.760Z","1.0.1":"2024-04-02T09:30:24.499Z"},"_id":"@1point6/1point6-js","name":"@1point6/1point6-js","dist-tags":{"latest":"1.0.1"},"versions":{"1.0.1":{"name":"@1point6/1point6-js","version":"1.0.1","description":"1point6.js loading wrapper","repository":{"type":"git","url":"git+https://github.com/get1point6/1point6-js.git"},"type":"module","types":"dist/index.d.ts","typings":"dist/index.d.ts","keywords":["1point6","1point6js","1point6.js","1point6.js loading wrapper"],"author":{"name":"1Point6","url":"https://get1point6.io/"},"main":"dist/1point6.es.js","scripts":{"start:dev":"nodemon --watch /src --exec 'tsc && vite build'","build":"tsc && vite build"},"devDependencies":{"@types/node":"^20.8.5","nodemon":"^3.0.1","typescript":"^5.0.2","vite":"^4.3.9","vite-plugin-dts":"^3.8.1"},"bugs":{"url":"https://github.com/get1point6/1point6-js/issues"},"homepage":"https://github.com/get1point6/1point6-js#readme","license":"MIT","private":false,"_id":"@1point6/1point6-js@1.0.1","gitHead":"4d1020b81411dc78548a2b4733d34655aee50fd0","_nodeVersion":"18.18.2","_npmVersion":"9.8.1","dist":{"integrity":"sha512-AwL1NdqnPWpKLp9sIcBGimZ0evVTpKV6RlUvrTqdRwzAyWzbVCNpRGOOsSzOY+wlhEbG/YIyXeEXnXa1bKzQNA==","shasum":"419b8c8b986d9e76590845dcd7bd78d18a685e76","tarball":"https://registry.npmjs.org/@1point6/1point6-js/-/1point6-js-1.0.1.tgz","fileCount":17,"unpackedSize":111301,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIBkft+2aOZJ5e+iQlP56ZZmxDwtFaPSDozKoXx5qo7zYAiBxWcaDtHO7Sb4XJbECoYwomdguRei42sn4c0RInsr+0A=="}]},"_npmUser":{"name":"gplumeyget1point6","email":"guillaume.plumey@get1point6.com"},"directories":{},"maintainers":[{"name":"gplumeyget1point6","email":"guillaume.plumey@get1point6.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/1point6-js_1.0.1_1712050224304_0.6890233747171974"},"_hasShrinkwrap":false}},"maintainers":[{"name":"gplumeyget1point6","email":"guillaume.plumey@get1point6.com"}],"description":"1point6.js loading wrapper","homepage":"https://github.com/get1point6/1point6-js#readme","keywords":["1point6","1point6js","1point6.js","1point6.js loading wrapper"],"repository":{"type":"git","url":"git+https://github.com/get1point6/1point6-js.git"},"author":{"name":"1Point6","url":"https://get1point6.io/"},"bugs":{"url":"https://github.com/get1point6/1point6-js/issues"},"license":"MIT","readme":"# Functional Perimeter\n\n**Accept payment methods from all over the world with an integrated and secure user interface component.**\n\nThe Payment Element is a user interface component for the Web that accepts more than one payment method, validates input, and manages errors. Use it alone or with other front-end elements of your Web application.\n\n# How It Works\n\n## Installation\n\n### Installation via our 1Point6JS library\n\n1Point6JS is a wrapper that simplifies loading 1point6 on your website. It ensures that it is only loaded once and offers TypeScript autocomplete.\n\n### Installation of 1Point6.js\n\nUse npm (for example) to install the 1Point6.js module:\n\n```jsx\nnpm install @1point6/1point6-js\n```\n\n## Usage\n\n### load1Point6\n\nThis function returns a promise that resolves with a newly created 1Point6 object once 1Point6.js has been loaded. It takes the same parameters as those passed during the direct initialization of a 1Point6 instance. If necessary, it will load 1Point6.js for you by inserting the 1Point6.js script tag. If you call load1Point6 in a server environment, it will resolve to null.\n\n```jsx\nimport { load1Point6 } from \"@1point6/1point6-js\";\n\nconst get1Point6 = await load1Point6(\n  publicApiKey, // \"public_0b38ef2f95c09ad0aa08\"\n  'sandbox', // \"sandbox\" or \"production\"\n  'my-sandbox-instance', // Only required if you are using the sandbox environment\n});\n```\n\n- **publicApiKey**: We have placed a random API key in this example. Replace it with your actual publishable API keys to test this code via your 1Point6 account. You can find your API keys in your 1Point6 Dashboard.\n- **env**: The environment in which to load 1Point6.js. Can be sandbox or production.\n\n### Manual Installation\n\nManually add the 1Point6.js script tag to the <head> of each page on your site. If an existing script tag is already present, this module will not insert a new one. When you call load1Point6, it will use the existing script tag.\n\n```jsx\n<!-- Somewhere in your site's <head> -->\n<script src=\"https://js.get1point6.com/\" async></script>\n```\n\n## 1) Creating a paymentIntent (Backend)\n\nOn the server side, proceed to create a paymentIntent on the route https://api.get1point6.com/payment-intents\n\nExample in PHP:\n\n```jsx\nfunction createPaymentIntent($items) {\n    $username = 'Your private key';\n    $password = \"\";\n\n    // Calculate your product totals on the back-end to avoid any manipulation of object in front\n    $calculateOrderAmount = function() use ($items) {\n        $itemTotal = 0;\n        foreach ($items as $item) {\n            $itemTotal += $item['quantity'] * $item['price'];\n        }\n        return $itemTotal;\n    };\n\n    $paymentIntentBody = [\n        'amount' => $calculateOrderAmount(),\n        'currency' => \"EUR\",\n        'return_url' => \"https://www.my-shop.com/order/cart/checkout-onshop\",\n        'transfer_data' => [\n            [\n                'destination' => 'Your accountID',\n                'amount' => $calculateOrderAmount(),\n                'application_fee' => 0,\n                'availability_type' => \"IMMEDIATE\"\n            ],\n        ],\n    ];\n\n    $ch = curl_init(\"https://api.get1point6.com/payment_intents\");\n    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);\n    curl_setopt($ch, CURLOPT_POST, true);\n    curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($paymentIntentBody));\n    curl_setopt($ch, CURLOPT_HTTPHEADER, [\n        \"Content-Type: application/json\",\n        \"Authorization: Basic \" . base64_encode($username . \":\" . $password)\n    ]);\n\n    $response = curl_exec($ch);\n    curl_close($ch);\n\n    $paymentIntent = json_decode($response, true);\n    return $paymentIntent['secret_key'];\n}\n```\n\nWith $items:\n\n```jsx\n// Replace with your backend product price retrieval logic\n\n$items = [\n    [\n        'quantity' => 2, // Quantity of item 1\n        'price' => 10.00 // Price of item 1\n    ],\n    [\n        'quantity' => 1, // Quantity of item 2\n        'price' => 20.00 // Price of item 2\n    ],\n        ...\n];\n```\n\n## 2) **Create a Payment Element (Frontend)**\n\nThis code creates a Payment Element and mounts it on the DOM:\n\n```jsx\nconst get1Point6 = await load1Point6(\"your public key\");\n\nconst appearance = {\n  /* appearance */\n};\nconst options = {\n  /* options */\n};\nconst elements = get1Point6.elements({ clientSecret, appearance }); // Replace clientSecret with your secret returned by the previously created paymentIntent\nconst paymentElement = await elements.create(\"payment\", options);\npaymentElement.mount(\"#payment-element\");\n```\n\n## (Optional) Appearance\n\nUse the Appearance API to control the style of all elements. Choose a theme or update specific information.\n\nFor example, choose the \"flat\" theme and replace the main text color.\n\n```\n\njsx\nconst get1Point6 = await load1Point6('your public key');\n\nconst appearance = {\n  theme: '1point6',\n  variables: {\n      colorPrimary: '#587a9d',\n      colorBackground: '#ff0000',\n      colorText: '#515581',\n    },\n};\nconst options = { /* options */ };\nconst elements = get1Point6.elements({ clientSecret, appearance }); // Replace clientSecret with your secret returned by the previously created paymentIntent\nconst paymentElement = await elements.create('payment', options);\npaymentElement.mount('#payment-element');\n```\n\n## 3) Making the Payment on the Client Side\n\nWhen your client clicks on the payment button, call **`confirmPayment()`** with the PaymentElement and pass a return_url to indicate the page to which 1Point6 should redirect the user once the payment is made. For payments requiring authentication, 1Point6 directly displays the 3DSecure authentication request or redirects the client to an authentication page, depending on the payment method. Once the authentication process is finalized, the client is redirected to the **`return_url`**.\n\n```jsx\ndocument\n        .querySelector(\"#payment-element\")!\n        .addEventListener(\"submit\", handleSubmit);\n\n      async function handleSubmit(e: any) {\n        const { error } = await get1Point6.confirmPayment({\n          elements,\n          confirmParams: {\n            return_url: `https://www.my-shop.com/order/success`,\n          },\n        });\n        // Error handling\n        if (error.type === \"card_error\" or error.type === \"validation_error\") {\n          console.error(error.message);\n        } else {\n          console.error(\"An unexpected error occurred.\");\n        }\n      }\n```\n\n### Error Handling\n\nIn the event of an immediate error (e.g., the card is declined), 1Point6.js returns an error. Display this error directly to your client so they can make another payment attempt.\n\n### Displaying a Message on the Payment Status\n\nWhen 1Point6 redirects the client to the return_url, the query parameter payment_intent_client_secret is added by 1Point6.js. Use it to retrieve the PaymentIntent in order to determine the data to display to your client.\n","readmeFilename":"README.md"}