Stripe Payments

Accounts

https://stripe.com/docs/connect/accounts

## Connect

1. Standard

https://stripe.com/docs/connect/standard-accounts

https://connect.stripe.com/oauth/authorize?response_type=code&client_id=ca_ER5reokV2DdpKTpMcGha4e1PE2Ws9bnv&scope=read_write

– After connect

“`
curl -X POST https://connect.stripe.com/oauth/token -d client_secret=sk_test_ZP9WbGeRb5CFvs4kWDBPR8Jc -d code=ac_ER68Fn6EbyR7TxEldQDHzf291Qec1GxT -d grant_type=authorization_code
“`

– Successfull

“`json
{
“access_token”: “sk_test_yyomURbMIhHSqTfMt2Nd1ZD8”,
“livemode”: false,
“refresh_token”: “rt_ER6AyW6ZyNVytV1IXDW0WMaT0vxMJZUaz4pXCo5TzDuYY9VL”,
“token_type”: “bearer”,
“stripe_publishable_key”: “pk_test_12KT0HWOwhOqnoYdk0hHAAC3”,
“stripe_user_id”: “acct_1DoTJvEUH4GKXr6Y”,
“scope”: “read_write”

“`

## Charges

Official Document : https://stripe.com/docs/connect/charges

**Direct charges:**

– The connected account is responsible for the cost of the Stripe fees, refunds, and chargebacks
– The payment itself appears as a charge in the connected account, not in your platform account
– Charges directly increase the connected account’s balance
– Your platform’s balance is only increased via application fees

**Destination charges**

– Your platform account is responsible for the cost of the Stripe fees, refunds, and chargebacks, handling these for the connected account
– The payment itself appears as a charge in your platform account, followed by an automatic allocation to the connected account, which decreases your platform’s balance and increases the connected account’s balance
– Platform fees are earned by allocating less than the entire charge amount to the connected account

**Separate charges and transfers**

The third approach is to create charges on the platform account and then separately transfer funds to the connected account. This approach is similar to creating destination charges, but provides greater flexibility over the flow of funds at the cost of a more complicated integration.

Using this approach:

– Your platform account is responsible for the cost of the Stripe fees, refunds, and chargebacks, handling these for the connected account
– The payment itself appears as a charge in your platform account, with a separate, manual allocation to the connected account, which decreases your platform’s balance and increases the connected account’s balance
– Funds from charges can be allocated to more than one connected account
– Platform fees are earned by allocating less than the entire charge amount to the connected account

 

#!/usr/bin/env ruby
require ‘stripe’

# Set your secret key: remember to change this to your live secret key in production
# See your keys here: https://dashboard.stripe.com/account/apikeys
Stripe.api_key = “sk_test_ZP9WbGeRb5CFvs4kWDBPR8Jc” # platform api key
# Stripe.api_key = “sk_test_yyomURbMIhHSqTfMt2Nd1ZD8”
CONNECTED_STRIPE_ACCOUNT_ID = “acct_1DoTJvEUH4GKXr6Y”

charge = Stripe::Charge.create({
:amount => 100,
:currency => “eur”,
:source => “tok_1DyERbLvrMKW6bhfe3ykifOj”,
:description => “Pay for practioner #{CONNECTED_STRIPE_ACCOUNT_ID}”
# :destination => {
# :account => “acct_1DoTkkLvrMKW6bhf”,
# }
},
:stripe_account => “#{CONNECTED_STRIPE_ACCOUNT_ID}”
)

puts charge.inspect

Payment Form :

Official : https://stripe.com/docs/stripe-js

Demo : https://jsfiddle.net/misostack/qrkp1uy9/9/

 

Summary:  Có 3 cách để tích hợp stripe payment dạng direct charge cho application.

1.User tự config api key cho app của mình thông qua app. Khi process payment hệ thống đọc api key của user và process direct payment cho user khi customer thanh toán

2.User authorize connect với account stripe của app. App lưu lại stripe_account_id để khi process payment hệ thống dùng api_key của app thực hiện direct payment cho user khi customer thanh toán

3.User authorize connect với account stripe của app. App lưu lại access_token, refresh token của user. Khi process payment hệ thống dùng access_token của user thực hiện direct payment cho user khi customer thanh toán.

C Dynamic Array

 

 

table {font-size: 100%;}

 

 


Dynamic arrays in C


 


  • Do-it-yourself dynamic array in C

 

    • Fact:
      • The C programming language does
        not have
        dynamic array
        as a language feature

      However:

      • The C programming language does
        have sufficient number
        of powerful features that
        a C programmer can
        implement
        dynamic array
        (among other things)
        using these features !!!


       

    • Features in C that
      enable you to
      implement your own
      dynamic array:
    •  
      • Memory management functions:

            malloc( )    (we will use calloc() for arrays)
            free( )
        

         


      • Pointer arithmetic:

            if  p  points to a[0] then

        *(p + i) is an alias for a[i]

         

        Graphically illustrated:



       

    • Steps to
      create a
      dynamic array
      (of any data type):
    •  
      • Define a
        reference variable
        (say p)
        of the desired data typeExample: suppose we want to
        create a dynamic array of
        double variables


           double*  p;       // reference variable to a double variable
        

         

        Illustrated:


         

      • Allocate memory cells for
        the array elements and
        make p
        point to the
        first array element:
      •  

         

      • The array elements
        can now be accessed as:
      •  

           *(p+0)      first array element
           *(p+1)      second array element
           *(p+2)      third array element
           ...

        *(p+i) ith array element

         



 


  • The calloc() function: memory allocation function
    for arrays

 

  • Fact:
    • Each computer system has its own
      peculiar
      memory alignment requirements


       

    • The malloc() function
      only alocate memory cells
      for one variable:
    •  
      • malloc(nBytes)
        will allocates a block of memory cells
        of
        at least
        nBytes bytes
        that us
        suitably aligned
        for any usage.


     

  • To allocate memory cells
    for N consecutive variable
    (= array)
    ,
    you must use this function:
  •  

        calloc( nElems, nBytes )

    Example:

    calloc( 10, 8 )
    // Allocate space for 10 elements of size 8 (= array of 10 double)

     

The calloc function:

  • The calloc()
    function allocates space
    for an array
    of
    nElems
    elements

    of
    size nBytes.Note:

    • The allocated space
      will alos be
      initialized to zeros.






 


  • Example: dynamic array

 

  • We have now learn everything
    we will need to
    build our own
    dynamic array
    in C


     

  • C program that illustrates a
    dynamic array of
    double variables:
  •  

       int main(int argc, char *argv[])
       {
           int i;
        
           double* p;    // We uses this reference variable to access
       		     // dynamically created array elements
       
           p = calloc(10, sizeof(double) );  // Make double array of 10 elements

    for ( i = 0; i < 10; i++ )
    *(p + i) = i; // put value i in array element i

    for ( i = 0; i < 10; i++ )
    printf(“*(p + %d) = %lf\n”, i, *(p+i) );


    free(p);
    // Un-reserve the first array

    putchar(‘\n’);

    p = calloc(4, sizeof(double) );
    // Make a NEW double array of 4 elements

    // ***** Notice that the array size has CHANGED !!! ****

    for ( i = 0; i < 4; i++ )
    *(p + i) = i*i; // put value i*i in array element i

    for ( i = 0; i < 4; i++ )
    printf(“*(p + %d) = %lf\n”, i, *(p+i) );

    free(p);
    // Un-reserve the second array
    }

     

    Output:


       *(p + 0) = 0.000000
       *(p + 1) = 1.000000
       *(p + 2) = 2.000000
       *(p + 3) = 3.000000
       *(p + 4) = 4.000000
       *(p + 5) = 5.000000
       *(p + 6) = 6.000000
       *(p + 7) = 7.000000
       *(p + 8) = 8.000000
       *(p + 9) = 9.000000

    *(p + 0) = 0.000000
    *(p + 1) = 1.000000
    *(p + 2) = 4.000000
    *(p + 3) = 9.000000

     


     

  • Example Program:
    (Demo above code)
    &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp
    &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp


  •  

    How to run the program:

    • Right click on link(s) and
      save in a scratch directory

     

  • To compile:
    gcc dyn-array1.c
  •  
  • To run:

    ./a.out





c-program-without-main-function

Write a C Program without using main function

Write a C or C++ program without using main function. We are allowed to change the entry point of the program from main() to any other function or remove the main() function altogether.

 

1. Using GCC _start function

 

As per C/C++ standard, main() is the starting point of any program in a hosted environment where a program uses the facilities of an operating system. But in a freestanding environment, where a program execution may take place without the benefit of an operating system, the starting point need not be main(). An OS kernel or embedded system environment would be good example of a freestanding environment.

It is worth pointing out that there are whole lot of other things that happens before main() function is executed. i.e. main() is not the first entry point of the program. If you’re using GCC, _start function is the entry point of a C program which makes a call to main(). The main job of _start function is to perform a few initialization tasks.

So we can say that main() is the entry point for your program from a programmers perspective and _start is the usual entry point from the Operating System perspective. We can override _start and ask the compiler for full control over what is happening right from the start by using "-nostartfiles" option.

 

 


 

2. Using static initializer

 

We can also use a static initializer to call any custom function before main is executed and we can use exit() function inside that custom function, so program will terminate and control will never reach the main() function.

 

Download   Run Code

Output:

Inside execute()

We can also make use of C++ class constructor to do the same.

 

Download   Run Code

Output:

Inside Constructor


 

3. Using Macro Arguments

 

The ## macro operator concatenates two separate tokens together to form a single token. Below function uses ## macro operator to hide main method. But the code still does make call to the main function behind the scenes, but just not in plain sight.

 

Ruby Web Applications Without Rails

Like many web developers, I got my start programming on the web with PHP. When you’re working with PHP it’s obvious how to start from scratch on a simple web app. Get out a .php file, two cups of HTML, a pinch of <?php ?> tags. Throw it in the oven and you’re done.

With Ruby, things aren’t so obvious. Virtually every Rubyist gets his or her start with a framework. You go along happily pecking out one line of code after another, never understanding what lies beneath the surface.

There are a few reasons you may want to ditch the framework and go bare-bones:

  • Speed – Rails can’t match just Rack for speed. A “Hello World!” in Rails takes about 1.13 seconds to render. A simple Rack application takes < 10 milliseconds. Rails has some tricks to bring that time down on subsequent requests, but from a cold start using shotgun, those are the numbers.
  • Size – Rails also uses a lot more memory than a bare-bones Rack application.
  • Simplicity – Rails creates a lot of files to wade through. Sometimes a single config.ru is enough.
  • Future-Proofing – Rails has a very aggressive release schedule and isn’t afraid to deprecate things and leaving vulnerabilities in old versions unpatched. Rack, on the other hand, tends to remain stable for long periods of time.

Don’t get me wrong, I love Rails. It’s my framework of choice for most of my projects. My rule of thumb is, if it’s dirt simple and won’t change much, go with just Rack. If it’s pretty simple and could change a bit, use Sinatra. Anything else, use Rails. I’ve started projects saying, “I won’t need all the stuff in Rails for this”, only to find myself going through the work of adding in most of what Rails would have given me out of the box.

What is Rack

Rack is the standard that all Ruby web servers use to interact with Ruby web applications. Rails is a Rack application. Sinatra is a Rack application. So are VoltLotusGrape and just about everything else.

Rack is both a standard for Ruby web apps and also a gem. It’s not necessary to use the gem but it does tend to make life easier.

Hello World With Rack

run -> env { [200, {'Content-Type' => 'text/plain'}, ['Hello World!']] }

There it is. That’s all you need to have a basic Rack app. Stick it in a config.ru file, run rackup and visit http://localhost:9292 and you should see your first bare-bones Ruby web app.

Now that we know that it works, let’s back up and figure out what exactly is going on here. We’ll take it step by step.

  • config.ru – The .ru stands for Rackup file. It’s just a Ruby file, but it’s designed to be read by a Ruby web server. If you try running ruby config.ru you’ll get an error.
  • run – This is a method defined by the Ruby web server. It expects a Rack application as an argument.
  • -> – This is called a stabby lambda. It’s shorthand for a anonymous function. Everything inside { } will be run when the #call method is called on it.
  • env – This is an argument for the lambda. Every Rack application must have a #call method that takes one argument. That argument is an environment hash which contains all the information about the HTTP request that was made.
  • [] – The return value of the #call method of a Rack app must be an array with three values.
  • 200 – The first element of the returned array is the status code to be returned.
  • {'Content-Type' => 'text/plain'} – This is a hash of the headers that will be sent with the HTTP response
  • ['Hello World'] – This is the body of the response. This is where HTML would normally go. Notice it’s a string wrapped in an array. Whatever object you give here must respond to #each, which a Ruby array does of course.

Making It Do Something

This is all fine and dandy, but what’s the point of having Ruby just spit out “Hello World!”. Let’s make it do something dynamic and useful.

run -> env { [200, {'Content-Type' => 'text/plain'}, ["Your IP: #{env['REMOTE_ADDR']}"]] }

There you have it. You have your very own super basic whatismyip.com clone in one line of code.

Making It Better

The code above works but it’s not a practical way to write an actual application. Let’s get a better structure going. Something that we can build off of.

class MyApp
  attr_reader :request

  def initialize(request)
    @request = request
  end

  def status
    if homepage?
      200
    else
      404
    end
  end

  def headers
    {'Content-Type' => 'text/html', 'Content-Length' => body.size.to_s}
  end

  def body
    content = if homepage?
      "Your IP: #{request.ip}"
    else
      "Page Not Found"
    end

    layout(content)
  end

  private

  def homepage?
    request.path_info == '/'
  end

  def layout(content)
%{<!DOCTYPE html>
<html lang="en">
  <head>

    <meta charset="utf-8">
    <title>Your IP</title>
  </head>
  <body>
    #{content}
  </body>
</html>}
  end
end

class MyApp::Rack
  def call(env)
    request = Rack::Request.new(env)
    my_app = MyApp.new(request)

    [my_app.status, my_app.headers, [my_app.body]]
  end
end

run MyApp::Rack.new

So that’s a lot of code for an app that doesn’t do much, but the point is to see how you can build out classes that feed into a bare-bones Rack app. You can see that a couple features were added like being HTML instead of plain text, and having a working 404 functionality and providing a Content-Length header.

If you’d like to see a real world example of a Rack-only application, check out the small app I wrote to be the backend of the contact form for this site.

 

Ref : https://codenoble.com/blog/ruby-web-applications-without-rails/

Rack : http://rack.github.io

Sinatra : https://github.com/sinatra/sinatra

Puma : https://github.com/puma/puma

Tiêu chí đánh giá phần mềm

Để đánh giá được sản phẩm của một nền công nghệ là tốt hay xấu, chúng ta phải nghiên cứu để đưa ra được những tiêu chuẩn đánh giá chúng. Chất lượng của sản phẩm phần mềm bao gồm nhiều yếu tố dựa trên các tiêu chuẩn đã được tổng kết.

Tính đúng

Một sản phẩm thực hiện được gọi là đúng nếu nó thực hiện chính xác những chức năng đã đặc tả và thỏa mãn các mục đích công việc của khách hàng.

Như vậy, một sản phẩm phải được so sánh chuẩn đặt ra để kiểm tra tính đúng và điều này dẫn đến có nhiều bậc thang về tính đúng.

Liệt kê theo thang giảm dần, tính đúng của phần mềm có thể:

+ Tuyệt đối đúng,

+ Đúng ,

+ Có lỗi,

+ Có nhiều lỗi,…

Ví dụ: Một hệ thống xử lý dữ liệu không chạy được khi file cơ sở dữ liệu rỗng hoặc có quá 104 bảng ghi,…là những hệ thống vi phạm tính đúng.

Tính khoa học

Tính khoa học của phần mềm được thể hiện qua các mặt

– Khoa học về cấu trúc.

– Khoa học về nội dung.

– Khoa học về hình thức thao tác.

Tính tin cậy

Tính tin cậy của sản phẩm phần mềm thể hiện ở sản phẩm được trông chờ thực hiện các chức năng dự kiến của nó với độ chính xác được yêu cầu.

Tính kiểm thử được

Phần mềm có thể kiểm thử được là phần mềm mà nó có cách dễ dàng để có thể kiểm tra được. Đảm bảo rằng nó thực hiện đúng các chức năng dự định.

Tính hữu hiệu

Tính hữu hiệu của phần mềm được xác định qua các tiêu chuẩn sau:

– Hiệu quả kinh tế hoặc ý nghĩa; giá trị thu được do áp dụng sản phẩm đó.

– Tốc độ xử lý sản phẩm.

– Giới hạn tối đa của sản phẩm hoặc miền xác định của chương trình được xác định qua khối lượng tối đa của các đối tượng mà sản phẩm đó quản lý.

Tính sáng tạo

Một sản phẩm phần mềm có tính sáng tạo khi nó thảo mãn một trong các tính chất sau:

– Sản phẩm được thiết kế và cài đặt đầu tiên.

– Sản phẩm được phục vụ cho những đặc thù riêng.

– Sản phẩm có những đặc điểm khác về mặt nguyên lý so với các sản phẩm hiện hành.

– Sản phẩm có những ưu thế nổi bậc so với sản phẩm hiện hành.

Tính an toàn

Tính an toàn của sản phẩm phần mềm được đánh giá thông qua:

– Có cơ chế bảo mật và bảo vệ các đối tượng do hệ thống phát sinh hoặc quản lý.

– Bản thân sản phẩm được đặt trong một cơ chế bảo mật nhằm chống sao chép trộm hoặc làm biến dạng sản phẩm đó.

Tính toàn vẹn

Sản phẩm phần mềm có tính toàn vẹn khi nó:

– Có cơ chế ngăn ngừa việc thâm nhập bất hợp pháp vào phần mềm hay dữ liệu và ngăn ngừa việc phát sinh ra những đối tượng (dữ liệu, đơn thể…) sai quy cách hoặc mâu thuẩn với các đối tượng sẳn có.

– Không gây ra nhập nhằng trong thao tác. Đảm bảo nhất quán về cú pháp.

– Có cơ chế phục hồi lại toàn bộ hoặc một phần những đối tượng thuộc toàn bộ hoặc một phần những đối tượng thuộc diện quản lý của sản phẩm trong trường hợp có sự cố như hỏng máy, mất điện đột ngột.

Tính đối xứng và đầy đủ chức năng

Sản phẩm cung cấp đủ các chức năng cho người sử dụng và các chức năng của sản phẩm có các cặp loại trừ lẫn nhau, ví dụ các chức năng đối xứng thường gặp:

+ Tạo lập – Hủy bỏ,

+ Thêm – Bớt (xem – xóa),

+ Tăng – Giảm,

+ Dịch chuyển lên – xuống; phải – trái,

+ Quay xuôi – ngược chiều kim đồng hồ,…

Tính tiêu chuẩn và tính chuẩn

Sản phẩm phần mềm cần đạt được một số tiêu chuẩn tối thiểu được thừa nhận trong thị trường hoặc trong khoa học, và có thể chuyển đổi dạng cấu trúc dữ liệu riêng của hệ thống sang chuẩn và ngược lại.

Tính chuẩn của phần mềm thể hiện ở sản phẩm đó phù hợp với các chuẩn quốc gia hoặc quốc tế.

Trong khi xây dựng phần mềm, cần tuân theo nguyên tắc chuẩn hoá sau:

+ Chỉ thiết kế và xây dựng phần mềm sau khi đã xác định được

chuẩn.

+ Mọi thành phần của phần mềm phải được thiết kế và cài đặt theo cùng một chuẩn (tối tiểu thì các chuẩn phải tương thích nhau).

Tính độc lập

Phần mềm cần và nên đảm bảo được tính độc lập với các đối tượng sau:

– độc lập với thiết bị,

– độc lập với cấu trúc của đối tượng mà sản phẩm đó quản lý,

– độc lập với nội dung của đối tượng mà sản phẩm đó quản lý.

Tính dễ phát triển, hoàn thiện

Thể hiện ở phần mềm có thể mở rộng cho các phương án khác hoặc mở rộng, tăng cường về mặt chức năng một cách rõ ràng.

Một số tính chất khác

Ngoài các tính chất trên, tuỳ theo công dụng mà sản phẩm phần mềm cần phải được bổ sung các tính chất sau:

1. Tính phổ dụng: có thể áp dụng cho nhiều lĩnh vực theo nhiều chế độ làm việc khác nhau.

2. Tính đơn giản: mang những yếu tố tâm lý: dễ thao tác, dễ học, dễ hoàn thiện kỹ năng khai thác sản phẩm, trong sáng, dễ hiểu, dễ nhớ…

3. Tính liên tác: là tính chất cần có để có thể gắn hệ thống này với hệ thống khác.

4. Tính súc tích: là độ gọn của chương trình tính theo số mã dòng lệnh.

5. Tính dung thứ sai lầm: tức là những hỏng hóc xuất hiện khi chương trình gặp phải lỗi được chấp nhận.

6. Tính module: là sự độc lập chức năng của các thành phần trong chương trình.

7. Tính đầy đủ hồ sơ: hệ thống phải có đầy đủ hồ sơ pháp lý khi xây dựng.

8. Tính theo dõi được, tính dễ vận hành,…

7 rules to make the greatest UI

7 luật về UI

1. Ánh sáng đến từ bầu trời
2. Trắng và Đen trước hết
3. Hãy tăng gấp đôi khoảng trắng
4. Phương pháp nhấn mạnh chữ trên nền ảnh
5. Kỹ thuật pop và un-pop
6. Chỉ dùng những font tốt
7. “Ăn trộm” như là một nghệ sỹ

IOS App publishing issues

Guideline 2.3.3 – Performance – Accurate Metadata

 

We noticed that your screenshots do not sufficiently reflect your app in use. Specifically, the app screenshots are from an Android device

Next Steps

To resolve this issue, please revise your screenshots to ensure that they accurately reflect the app in use. For resources on creating great screenshots for the App Store, you may want to review the App Store Product Page information available on the Apple developer portal.

Please ensure you have made any screenshot modifications using Media Manager. You should confirm your app looks and behaves identically in all languages and on all supported devices. Learn how to use Media Manager to add custom screenshots for each display size and localization.

Since your iTunes Connect status is Rejected, a new binary will be required. Make the desired metadata changes when you upload the new binary.

NOTE: Please be sure to make any metadata changes to all app localizations by selecting each specific localization and making appropriate changes.

 

Guideline 2.3.10 – Performance – Accurate Metadata

 

We noticed that your app or its metadata includes irrelevant third-party platform information. Specifically, the app screenshots are from an Android device.

Referencing third-party platforms in your app or its metadata is not permitted on the App Store.

Next Steps

To resolve this issue, please remove all instances of this information from your app and its metadata, including the app description, What’s New info, previews, and screenshots.

 

Guideline 3.1.1 – Business – Payments – In-App Purchase

 

We found that your app offers in-app purchases that can be restored but does not include a “Restore Purchases” feature to allow users to restore the previously purchased in-app purchases, as specified in the “Restoring Purchase Products” section of the In-App Purchase Programming Guide:

“Users restore transactions to maintain access to content they’ve already purchased. For example, when they upgrade to a new phone, they don’t lose all of the items they purchased on the old phone. Include some mechanism in your app to let the user restore their purchases, such as a Restore Purchases button.”

Note —
Non-consumable in-app purchase items should always contain a restore button so users can restore the purchase if they opt to not make an account. Requiring an account to purchase or restore non-consumable in-app purchase items is not appropriate.

To restore previously purchased in-app purchase products, it would be appropriate to provide a “Restore” button and initiate the restore process when the “Restore” button is tapped by the user.

 

Guideline 3.1.4 – Business – Payments – Content Codes

 

Your app unlocks or enables additional functionality with mechanisms such as promo codes, license keys, augmented reality markers, or QR codes, which is not appropriate for the App Store. Using a code to unlock content (both the trial and full verion) is not appropriate.

Next Steps

To resolve this issue, please remove any code functionality from your app.

Tạo trang giống vầy với WordPress.com
Hãy bắt đầu