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

  1. WebPay Charge
    • WebPay cung cấp cho người dùng api sử dụng cho thanh toán, được định nghĩa trong function
    webpay.charge.create()
+ Ví dụ về 1 `request`
    webpay = WebPay.new("test_secret")
    webpay.charge.create(
       amount: 400,
       currency: "jpy",
       card: "tok_SampleCardToken",
       description: nil
    )
Response:
    #<WebPay::ChargeResponse
      id: "ch_1q78in60y1QR64G"
      object: "charge"
      livemode: false
      currency: "jpy"
      description: nil
      amount: 400
      amount_refunded: 0
      customer: nil
      recursion: nil
      created: 1461031804
      paid: true
      refunded: false
      failure_message: nil
      card: #<WebPay::CardResponse
          object: "card"
          exp_year: 2018
          exp_month: 8
          fingerprint: "215b5b2fe460809b8bb90bae6eeac0e0e0987bd7"
          name: "TARO YAMADA"
          country: "JP"
          type: "Visa"
          cvc_check: "pass"
          last4: "4242"
      >
      captured: true
      expire_time: nil
      fees: [#<WebPay::ChargeFeeResponse
          object: "fee"
          transaction_type: "payment"
          transaction_fee: 0
          rate: 3.25
          amount: 13
          created: 1461031804
      >]
    >
- Ý nghĩa của các `Object`

| Property | Child Property | Model | Value of explain|
| ------------- |-----------| -----| ----------------------------|
|id| |string|start to `ch_`. This is unique of string|
|object| |object|object value is "charge"|
|livemode| |boolean|	`true` is `production environment` <br>`false` is `test environment`|
|amount| |integer|This is price<br>This is charge Unit of One yen(¥)|
|card| |hash(bring dictionary)|	billing of Credit Card information 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|
| |type|string|This is Card Brand(Visa, MasterCard, <br> 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|
|created||timestamp|created at |
|currency| |string|ISO code name (for example japan is : `jpy`)|
|paid| |boolean|Securing lines of credit <br>If Provisional sales or Actual sales<br> success : `true` failed sales : `false`|
|captured| |boolean|uuid	-	string	uuid of RFC 4122  (default null)finish of sales : `true`<br> not finish of sales : `false`|
|refunded| |boolean|Billing is refund : `true`<br>Billing is not refund : `false`|
|amount_refunded| |integer|Refunded of price. Unit of yen |
|customer| |string|customer ID|
|shop| |string|Shop ID|
|recursion| |string|Regular purchases ID|
|description| |string|This is unique of charge object.<br>If you manage user, when you will <br>implement add e-mail and user id for tracking,<br> This is so good |
|failure_message| |string|failure detail message of charge,<br> in case failed charge|
|expire_time| |timestamp|Unix time of provisional account sales |
|fees||array(inclued of hash)|List of Commission|
| |object|string|value is `fee`|
| |transaction_type|string|How do occur commission to transaction payment or refund|
| |transaction_fee|integer|occur commission by each transaction. This is unit of yen|
| |rate||Percentage of commission|
| |amount|integer|price of commission|
| |created|timestamp|create at|
|uuid| |string|uuid of RFC 4122 (default null)|

+ Trong trường hợp có vấn đề xảy ra với thanh toán, `WebPay` cũng cung cấp cho ta phương thức `Refund Charge` để trả lại cho khách hàng số tiền đã thanh toán
    webpay.charge.refund()
+ Ví dụ 1 `request refund`
    webpay = WebPay.new("Test_secret")
    webpay.charge.refund(id: "ch_1q78in60y1QR64G")
`Response` trả về:
    #<WebPay::ChargeResponse
      id: "ch_1q78in60y1QR64G"
      object: "charge"
      livemode: false
      currency: "jpy"
      description: nil
      amount: 400
      amount_refunded: 400
      customer: nil
      recursion: nil
      created: 1461031804
      paid: true
      refunded: true
      failure_message: nil
      card: #<WebPay::CardResponse
          object: "card"
          exp_year: 2018
          exp_month: 8
          fingerprint: "215b5b2fe460809b8bb90bae6eeac0e0e0987bd7"
          name: "TARO YAMADA"
          country: "JP"
          type: "Visa"
          cvc_check: "pass"
          last4: "4242"
      >
      captured: true
      expire_time: nil
      fees: [#<WebPay::ChargeFeeResponse
          object: "fee"
          transaction_type: "payment"
          transaction_fee: 0
          rate: 3.25
          amount: 13
          created: 1461031804
      >]
    >
+ Get Charge List
`WebPay` cung cấp cho người dùng `function` để lấy ra list các thanh toán của các user được định nghĩa trong:
     webpay.charge.all()
+ Ví dụ về 1 `request` lấy ra 3 thanh toán gần nhất
    webpay = WebPay.new("test_secret")
    webpay.charge.all(count: 3)
    #<WebPay::ChargeResponseList
      object: "list"
      url: "/v1/charges"
      count: 3
      data: [#<WebPay::ChargeResponse
        id: "ch_1q78in60y1QR64G"
        object: "charge"
        livemode: false
        currency: "jpy"
        description: nil
        amount: 400
        amount_refunded: 0
        customer: nil
        recursion: nil
        created: 1461031804
        paid: true
        refunded: false
        failure_message: nil
        card: #<WebPay::CardResponse
            object: "card"
            exp_year: 2018
            exp_month: 8
            fingerprint: "215b5b2fe460809b8bb90bae6eeac0e0e0987bd7"
            name: "TARO YAMADA"
            country: "JP"
            type: "Visa"
            cvc_check: "pass"
            last4: "4242"
        >
        captured: true
        expire_time: nil
        fees: [#<WebPay::ChargeFeeResponse
            object: "fee"
            transaction_type: "payment"
            transaction_fee: 0
            rate: 3.25
            amount: 13
            created: 1461031804
        >]
      >]
    >
+ Thông tin doanh số thực tế (phí của `webpay`)
`WebPay` cung cấp `api` cho người dùng có thể thấy được số tiền phí của dịch vụ và số tiền thực tế của người dùng nhận về , trạng thái `refund` của 1 đơn thanh toán
    webpay.charge.capture()
Ví dụ:
    webpay = WebPay.new("test_secret")
    webpay.charge.capture(id: "ch_id")
    #<WebPay::ChargeResponse
      id: "ch_1q78in60y1QR64G"
      object: "charge"
      livemode: false
      currency: "jpy"
      description: nil
      amount: 400
      amount_refunded: 0
      customer: nil
      recursion: nil
      created: 1461031804
      paid: true
      refunded: false
      failure_message: nil
      card: #<WebPay::CardResponse
          object: "card"
          exp_year: 2018
          exp_month: 8
          fingerprint: "215b5b2fe460809b8bb90bae6eeac0e0e0987bd7"
          name: "TARO YAMADA"
          country: "JP"
          type: "Visa"
          cvc_check: "pass"
          last4: "4242"
      >
      captured: true
      expire_time: 1461636604
      fees: [#<WebPay::ChargeFeeResponse
          object: "fee"
          transaction_type: "payment"
          transaction_fee: 0
          rate: 3.25
          amount: 13
          created: 1461031804
      >]
    >