Skip to content

Instantly share code, notes, and snippets.

@onesup
Last active November 21, 2016 21:29
Show Gist options
  • Save onesup/19fbc76caf9a8e8b4526e08336baa9da to your computer and use it in GitHub Desktop.
Save onesup/19fbc76caf9a8e8b4526e08336baa9da to your computer and use it in GitHub Desktop.
ror-class-second-day
<script src="https://service.iamport.kr/js/iamport.payment-1.1.2.js" type="text/javascript"></script>
<script>
IMP.init('imp34166162');
IMP.request_pay({
pg : 'kakao',
pay_method : 'card',
merchant_uid : 'merchant_' + new Date().getTime(),
name : '주문명:결제테스트',
amount : 14000,
buyer_email : 'iamport@siot.do',
buyer_name : '구매자이름',
buyer_tel : '010-1234-5678',
buyer_addr : '서울특별시 강남구 삼성동',
buyer_postcode : '123-456'
}, function(rsp) {
if ( rsp.success ) {
$('#payment_imp_uid').val(rsp.imp_uid);
$('#payment_merchant_uid').val(rsp.merchant_uid);
$('#payment_paid_amount').val(rsp.paid_amount);
$('#payment_apply_num').val(rsp.apply_num);
} else {
$('#payment_error_msg').val(rsp.error_msg);
}
});
</script>
<h1>New Payment</h1>
<%= render 'form' %>
<%= link_to 'Back', payments_path %>

수업자료

#[fit] bit.ly/ror-second-day


strong parameter

  • 컨트롤러 파일
params.require(:product).permit(:name, :provider_id)
  • active admin 파일
permit_params :name, :provider_id, :contents_image

스트롱 파라미터 한글 가이드

사용자가 보안 상의 이유로 변경해서는 안되는 속성을 실수로 변경할 수 없게끔 방지하기 위한 방책


스트롱 파라미터

  • User 가 role 이라는 컬럼을 가지고 있다.
  • role 은 admin, customer 두 가지 값을 가질 수 있다.
  • 이런 경우 Controller 마다 strong parameter 제한을 걸어둘 수 있다.
  • Customer User 가 접근하는 Controller 에서는 role 값을 변경 할 수 없게 설정.
  • Admin User 가 접근하는 Controller 에서는 role 값 변경 가능하게 설정.

보안 문제 해결


active admin 심화

한 파일에 controller, view 가 같이 있음.


ruby 익명함수

표현식을 통째로 함수에 전달 할 때 사용

루비와 익명 함수


Route 개념 소개

http://guides.rorlab.org/routing.html


rest 개념 소개

CRUD: Create Read Update Delete

CRUD -> Create Get Put Delete

회원 관리

devise

rails g devise user rails g devise admin_user


장바구니

가입한 고객이나, 미가입 고객이 아직 주문 처리 안된 상품 목록을 가지고 있다.


장바구니 만들기 전략

current_user

  • 가입 후 로그인 한 고객
  • 미가입 고객
  • 시스템에 저장 안하고 세션 처리
  • 미식별 고객으로 강제 가입 처리 후 로그인

고객, 구매목록, 주문의 관계

current_user has_many :orders
order has_many :order_items
current_user has_many :order_items :through => orders

장바구니

current_user has_many order_items without order

헬결제

실무에서 카드결제 붙이는 일은 생각보다 까다로움. background


아임포트

아임포트 가입 시스템설정 -> PG 설정 -> 카카오페이

내정보의 아래 코드 메모 필요 가맹점 식별코드 rest api key rest api secret


결제 요청

PG 에서 요청하는 정보 merchant_uid : 'merchant_' + new Date().getTime() 주문방법: 카드결제 주문명('볏짚삼겹살 4인 세트 교환권 주문') 가격 구매자 이름 구매자 이메일 구매자 전화번호 구매자 주소 구매자 우편번호


결제 페이지

rails g scaffold payment order:references imp_uid merchant_uid paid_amount apply_num error_msg:text

view/payments/new.html.erb

<script src="https://service.iamport.kr/js/iamport.payment-1.1.2.js" type="text/javascript"></script>
gem 'iamport', github: 'iamport/iamport-rest-client-ruby'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment