Share 2Checkout & Reactjs & Laravel # 6

00 từ # 2checkout # ReactJS # Laravel # Thương mại điện tử ** Cách tích hợp 2Checkout với ReactJS và Laravel **

2Checkout là một cổng thanh toán cho phép các doanh nghiệp chấp nhận thanh toán trực tuyến.Reactjs là một thư viện JavaScript để xây dựng giao diện người dùng.Laravel là một khung PHP để xây dựng các ứng dụng web.Trong hướng dẫn này, chúng tôi sẽ chỉ cho bạn cách tích hợp 2Checkout với ReactJ và Laravel để tạo ra một cửa hàng thương mại điện tử hoạt động đầy đủ.

## Điều kiện tiên quyết

Để làm theo hướng dẫn này, bạn sẽ cần những điều sau đây:

* Tài khoản 2Checkout
* Một dự án Laravel
* Các gói Reactjs và Axios

## 1. Tạo tài khoản 2Checkout

Để tạo tài khoản 2Checkout, hãy truy cập [trang web 2Checkout] (https://www.2checkout.com/) và nhấp vào nút "Đăng ký".Nhập địa chỉ email và mật khẩu của bạn, sau đó nhấp vào nút "Tạo tài khoản".

Khi bạn đã tạo tài khoản của mình, bạn sẽ được nhắc nhập thông tin thẻ tín dụng của bạn.Bạn cũng có thể chọn thêm tài khoản ngân hàng hoặc tài khoản PayPal.

## 2. Tạo một dự án Laravel

Để tạo dự án Laravel, hãy sử dụng lệnh sau:

`` `
Nhà soạn nhạc tạo ra dự án Laravel/Laravel My-Excerce-Store
`` `

Điều này sẽ tạo ra một dự án Laravel mới có tên là "My-Excerce-Store".

## 3. Cài đặt các gói Reactjs và Axios

Để cài đặt các gói Reactjs và Axios, hãy sử dụng các lệnh sau:

`` `
NPM cài đặt React-DOM
NPM Cài đặt Axios
`` `

## 4. Tạo thành phần ReactJS cho trang thanh toán

Để tạo thành phần ReactJS cho trang thanh toán, hãy tạo một tệp mới có tên là `Checkout.js` trong thư mục` resource/js/thành phần`.

`` `JS
Nhập phản ứng, {Thành phần} từ "React";
Nhập các trục từ "Axios";

Thanh toán lớp mở rộng thành phần {
Constructor (đạo cụ) {
Super (đạo cụ);

this.state = {
paymentMethod: null,
số thẻ: "",
Hết hạn thẻ: "",
cardcvv: "",
};
}

Handlechange = (e) => {
this.setState ({
[E.Target.name]: E.Target.value,
});
};

Handlesubmit = (e) => {
E.PreventDefault ();

const {paymentMethod, cardNumber, cardExpiration, cardcvv} = this.state;

AXIOS.POST ("https://www.2checkout.com/api/rest/v2/charges", {
PaymentMethod: PaymentMethod,
CardNumber: CardNumber,
CardExpiration: CardExpiration,
cardcvv: cardcvv,
})
.then ((phản hồi) => {
Console.log (Phản hồi);
})
.catch ((lỗi) => {
Console.log (lỗi);
});
};

render () {
trở lại (
<form onsubmit = {this.handlesubmit}>
<Div>
<gable> Phương thức thanh toán </nhãn>
<chọn name = "paymayMethod" onchange = {this.handlechange}>
<tùy chọn value = "thẻ"> Thẻ tín dụng </tùy chọn>
<tùy chọn value = "BankAccount"> Tài khoản ngân hàng </tùy chọn>
<tùy chọn value = "paypal"> paypal </tùy chọn>
</chọn>
</div>
<Div>
<gable> Số thẻ </Nhãn>
<input type = "text" name = "cardNumber" onchange = {this.handlechange} />
</div>
<Div>
<gable> Hết hạn thẻ </nhãn>
không
</div>
<Div>
<gable> Thẻ CVV </Nhãn>
<input type = "text" name = "cardcvv" onchange = {this.handlechange} />
</div>
<nút loại = "Gửi"> Gửi </nút>
</Form>
);
}
}

Xuất thanh toán mặc định;
`` `

## 5. Thêm trang thanh toán vào tệp định tuyến Laravel

Để thêm trang thanh toán vào tệp định tuyến Laravel, hãy mở tệp `Route/Web.php` và thêm tuyến sau:

`` `PHP
Tuyến đường :: get ("/thanh toán", function () {
Quay trở lại ("Thanh toán");
});
=======================================
00 words # 2Checkout # Reactjs # Laravel # e-commerce **How to Integrate 2Checkout with ReactJS and Laravel**

2Checkout is a payment gateway that allows businesses to accept payments online. ReactJS is a JavaScript library for building user interfaces. Laravel is a PHP framework for building web applications. In this tutorial, we will show you how to integrate 2Checkout with ReactJS and Laravel to create a fully functioning e-commerce store.

## Prerequisites

To follow this tutorial, you will need the following:

* A 2Checkout account
* A Laravel project
* The ReactJS and axios packages

## 1. Create a 2Checkout account

To create a 2Checkout account, visit the [2Checkout website](https://www.2checkout.com/) and click the "Sign Up" button. Enter your email address and password, and then click the "Create Account" button.

Once you have created your account, you will be prompted to enter your credit card information. You can also choose to add a bank account or PayPal account.

## 2. Create a Laravel project

To create a Laravel project, use the following command:

```
composer create-project laravel/laravel my-ecommerce-store
```

This will create a new Laravel project called "my-ecommerce-store".

## 3. Install the ReactJS and axios packages

To install the ReactJS and axios packages, use the following commands:

```
npm install react react-dom
npm install axios
```

## 4. Create a ReactJS component for the checkout page

To create a ReactJS component for the checkout page, create a new file called `Checkout.js` in the `resources/js/components` directory.

```js
import React, { Component } from "react";
import axios from "axios";

class Checkout extends Component {
constructor(props) {
super(props);

this.state = {
paymentMethod: null,
cardNumber: "",
cardExpiration: "",
cardCVV: "",
};
}

handleChange = (e) => {
this.setState({
[e.target.name]: e.target.value,
});
};

handleSubmit = (e) => {
e.preventDefault();

const { paymentMethod, cardNumber, cardExpiration, cardCVV } = this.state;

axios.post("https://www.2checkout.com/api/rest/v2/charges", {
paymentMethod: paymentMethod,
cardNumber: cardNumber,
cardExpiration: cardExpiration,
cardCVV: cardCVV,
})
.then((response) => {
console.log(response);
})
.catch((error) => {
console.log(error);
});
};

render() {
return (
<form onSubmit={this.handleSubmit}>
<div>
<label>Payment Method</label>
<select name="paymentMethod" onChange={this.handleChange}>
<option value="card">Credit Card</option>
<option value="bankAccount">Bank Account</option>
<option value="PayPal">PayPal</option>
</select>
</div>
<div>
<label>Card Number</label>
<input type="text" name="cardNumber" onChange={this.handleChange} />
</div>
<div>
<label>Card Expiration</label>
<input type="text" name="cardExpiration" onChange={this.handleChange} />
</div>
<div>
<label>Card CVV</label>
<input type="text" name="cardCVV" onChange={this.handleChange} />
</div>
<button type="submit">Submit</button>
</form>
);
}
}

export default Checkout;
```

## 5. Add the checkout page to the Laravel routing file

To add the checkout page to the Laravel routing file, open the `routes/web.php` file and add the following route:

```php
Route::get("/checkout", function () {
return view("checkout");
});
 
Join ToolsKiemTrieuDoGroup
Back
Top
AdBlock Detected

We get it, advertisements are annoying!

Sure, ad-blocking software does a great job at blocking ads, but it also blocks useful features of our website. For the best site experience please disable your AdBlocker.

I've Disabled AdBlock