12/08/2018, 13:48

Sử dụng WebPay trong thanh toán trực tuyến

I. Giới thiệu 1. Webpay - API này được tạo nên từ nền của REST. Đó là một phương thức được dùng cho các nhà phát triển, sử dụng các URL của các nguồn tài nguyên theo định hướng, bằng cách sử dụng mã phản hồi HTTP để hiển thị các lỗi của API - API đang gia tăng cùng các tính năng HTTP xác thực HTTP. ...

I. Giới thiệu 1. Webpay - API này được tạo nên từ nền của REST. Đó là một phương thức được dùng cho các nhà phát triển, sử dụng các URL của các nguồn tài nguyên theo định hướng, bằng cách sử dụng mã phản hồi HTTP để hiển thị các lỗi của API - API đang gia tăng cùng các tính năng HTTP xác thực HTTP. Nói cách khác, nó có thể sử dụng đơn giản, theo API hiện diện trong tất cả các khách hàng và các công nghệ truyền thông HTTP có sẵn. - Không chỉ có khóa API cho production, tất cả người dùng sẽ có thể sử dụng khóa API của chế độ test và kiểm tra đầy đủ các chức năng của API - Các API của WebPay, chẳng hạn như thanh toán và mô tả khách hàng bao gồm nhiều giá trị mà nhà phát triển có thể thiết lập các giá trị khác nhau - Nếu bạn đã mua các mặt hàng này thông qua các API, tất cả các giá trị được trả về. - Nếu bạn muốn sử dụng trong các mục thiết lập miễn phí trong SQL hoặc hiển thị trên các trang HTML, nếu bạn không đúng cách thoát khỏi chuỗi, chúng có thể gây ra một vấn đề an ninh. 2. Xác thực - Bạn có thể được chứng thực bằng cách gửi có trong yêu cầu của một trong những chìa khóa API sở hữu. - Có 2 chế độ khóa của API cho môi trường production hoặc test, có một sự kết hợp của 2 × 2 của khóa public và private - Trong khóa API cho các môi trường production được thực hiện xử lý thẻ tín dụng thực tế, kiểm tra tính năng chỉ như các bài kiểm tra cho số thẻ là không có sẵn. 3. Thư viện của Ruby - Hỗ trợ với CRuby từ version 2.0 - Được cung cấp bởi RubyGems.org - Sử dụng command line

            $ gem install webpay
    - Sử dụng bunlder bằng cách add vào `Gemfile`
            gem 'webpay', '~>3.2'
4. WebPay
    - Create `webpay` client
            WEBPAY = WebPay.new ENV["WEBPAY_SECRET_KEY"]
    - Create `webpay` `card_token`
        + Định nghĩa trong phương thức
                webpay.token.create()
                webpay = WebPay.new('test_secret_zzzz')
                webpay.token.create(
                   card:
                    {number: "4242-4242-4242-4242",
                     exp_month: 11,
                     exp_year: 2017,
                     cvc: "123",
                     name: "KEI KUBO"}
                )
        Response
                #<WebPay::TokenResponse
                  id: "tok_1ufaE1bmbeGSglk"
                  object: "token"
                  livemode: false
                  created: 1461115295
                  used: false
                  card: #<WebPay::CardResponse
                    object: "card"
                    exp_year: 2017
                    exp_month: 11
                    fingerprint: "215b5b2fe460809b8bb90bae6eeac0e0e0987bd7"
                    name: "KEI KUBO"
                    country: "jp"
                    type: "Visa"
                    cvc_check: "pass"
                    last4: "4242"
                  >
                >
    - Token Object<br>
Property Child Property Model Value of explain
id - string start to "tok_" This is unique of string
object - object object value is "charge"
livemode - boolean true is "production environment"
false is "test environment"
created - integer This is price
This is charge Unit of One yen(¥)
card - hash(bring dictionary) billing of Credi Card information
connect to customer value is hash
object string Value is "card"
exp_year integer
exp_month integer
fingerprint string This is key of unique by CreditCard.
name string This is Name of CreditCard
country string country code
Currently , This is "JP"
type string This is Card Brand (Visa, MasterCard, American Express,
Discover, JCB, Diners Club or "unknown")
card cvc_check string check of security code "pass" or "fail" or "unchecked"
card last4 string last 4 number of CreditCard
used - string This is unique of customer object.
If you manage user,
when you will implement add e-mail and
user id for tracking , This is so good
  • Webpay Customer
    • Định nghĩa trong phương thức
            webpay.token.create()
            webpay.customer.create(
              card: "tok_SampleCardToken",
              description: "Awesome Customer"
            )
    Response
            #<WebPay::CustomerResponse
              id: "cus_1GDcXwe3u3he411"
              object: "customer"
              livemode: false
              created: 1461295810
              email: nil
              description: "Awesome Customer"
              active_card: #<WebPay::CardResponse
                object: "card"
                exp_year: 2021
                exp_month: 4
                fingerprint: "215b5b2fe460809b8bb90bae6eeac0e0e0987bd7"
                name: "KEI KUBO"
                country: "JP"
                type: "Visa"
                cvc_check: "pass"
                last4: "4242"
              >
              recursions: []
            >
    + Lấy thông tin của khách hàng
            webpay.customer.retrieve("cus_token_sample")
    Response
            #<WebPay::CustomerResponse
              id: "cus_1GDcXwe3u3he411"
              object: "customer"
              livemode: false
              created: 1461295810
              email: nil
              description: "Awesome Customer"
              active_card: #<WebPay::CardResponse
                object: "card"
                exp_year: 2021
                exp_month: 4
                fingerprint: "215b5b2fe460809b8bb90bae6eeac0e0e0987bd7"
                name: "KEI KUBO"
                country: "JP"
                type: "Visa"
                cvc_check: "pass"
                last4: "4242"
              >
              recursions: []
            >
  • Customer Object
Property Child Property Model Value of explain
id - string start to "cus_" This is unique of string
object - object object value is "charge"
livemode - boolean true is "production environment"
false is "test environment"
created - integer This is price
This is charge Unit of One yen(¥)
active_card - hash(bring dictionary) billing of Credi Card
information connect to
customer value is hash
object string Value is "card"
exp_year integer
exp_month integer
active_card fingerprint string This is key of unique by CreditCard.
name string This is Name of CreditCard
country string country code Currently, This is "JP"
type string This is Card Brand(Visa, MasterCard,
American Express, Discover,
JCB, Diners Club or "unknown")
cvc_check string check of security code
"pass" or "fail" or "unchecked"
last4 string last 4 number of CreditCard
description - string This is unique of customer object.
If you manage user, when you
will implement add e-mail and user id for tracking
, This is so good
recursions - array(inclued of hash) connect to customer of recursions information
email - string email (default is null)
uuid - string uuid of RFC 4122 (default null)
0