0
고객에게 카드를 추가하는 데 문제가 있습니다. 스트라이프 요청을 처리하는 간단한 익스프레스 서버를 만들었습니다. 현재 새로운 고객을 등록하고 있지만 새로운 고객에게 신용 카드 정보를 추가하는 데 실패합니다.스트라이프가 고객에게 카드를 추가하지 않음 - 각도 2/익스프레스
내 2 각도 응용 프로그램에서 나는 신용 카드 정보를 수집하여 내 Express Server로 보냅니다.
Something is happening.
post incomming
reg: { '{\n "id": "tok_19ASCZAgR5ZaHhRaLhfk7vcB",\n "object": "token",\n "card": {\n "id": "card_19ASCYAgR5ZaHhRaQZbBj5uj",\n "object": "card",\n "addr
ess_city": null,\n "address_country": null,\n "address_line1": null,\n "address_line1_check": null,\n "address_line2": null,\n "address_state": null
,\n "address_zip": null,\n "address_zip_check": null,\n "brand": "Visa",\n "country": "US",\n "cvc_check": "unchecked",\n "dynamic_last4": null,\
n "exp_month": 12,\n "exp_year": 2017,\n "funding": "credit",\n "last4": "4242",\n "metadata": {},\n "name": null,\n "tokenization_method": nu
ll\n },\n "client_ip": "90.210.15.78",\n "created": 1477868095,\n "livemode": false,\n "type": "card",\n "used": false\n}': '' }
customer: { id: 'cus_9TP0BdARBgZ0NF',
object: 'customer',
account_balance: 0,
created: 1477868096,
currency: null,
default_source: null,
delinquent: false,
description: null,
discount: null,
email: null,
livemode: false,
metadata: {},
shipping: null,
sources: { object: 'list',
data: [],
has_more: false,
total_count: 0,
url: '/v1/customers/cus_9TP0BdARBgZ0NF/sources' },
subscriptions:
{ object: 'list',
data: [],
has_more: false,
total_count: 0,
url: '/v1/customers/cus_9TP0BdARBgZ0NF/subscriptions' } }
Unhandled rejection Error: Cannot charge a customer that has no active card
그리고 내 코너 2 응용 프로그램 구성 요소 및 서비스를 다음에이 명시 서버에서 다음과 같은 응답을 얻기 Express 서버
router.post('/charge', function(req, res) {
console.log('post incomming');
console.log('reg:', req.body)
var token = req.body.id;
stripe.customers.create({
token: token
}).then(function(customer) {
console.log('customer:', customer)
return stripe.charges.create({
amount: 1000, // Amount in cents
currency: "eur",
customer: customer.id
});
}).then(function(err, charge) {
if(err) {
console.log('shomething wrong', err);
}
if(charge) {
console.log('charge done');
};
});
});
.
import { Component, OnInit, NgZone } from '@angular/core';
import { CheckoutService } from './checkout.service';
declare var Stripe:any;
@Component({
selector: 'app-stripe',
templateUrl: './stripe.component.html',
styleUrls: ['./stripe.component.css'],
})
export class StripeComponent implements OnInit {
private cardToken:any;
constructor(private checkoutService:CheckoutService, private _zone: NgZone) {
}
ngOnInit(){
}
setUpCard() {
//here we setup the stripe publish key.
//notice that this is a test key for my account so replace with production key(live)
Stripe.setPublishableKey('PUBKEYHERE');
}
getCardData(number, month, year, cvc) {
//I get the card data typed in here and pass it to the getCardToken method
this.getCardToken(number, month, year, cvc);
}
getCardToken(number, month, year, cvc) {
//set up the card data as an object
var dataObj = {"number": number, "exp_month": month, "exp_year": year, "cvc": cvc};
// Request a token from Stripe:
Stripe.card.createToken(dataObj,
(status, response) => { //I'm using an arrow function instead of stripeResponseHandler(a function also) cos it's kickass!
// basically you can do anything here with the reponse that has your token
// you can hit your backend api and initialize a charge etc
this._zone.run(() => {
if (status === 200) {
this.cardToken = response;
console.log("the card token: ", this.cardToken);
this.checkoutService.postToken(this.cardToken);
}
else {
console.log("error in getting card data: ", response.error)
}
});
}
);
}
}
체크 아웃 서비스
import { Injectable } from '@angular/core';
import { Http, Headers } from '@angular/http';
import { Observable } from 'rxjs/Rx';
@Injectable()
export class CheckoutService {
constructor(private http:Http) { }
postToken(token) {
console.log('from the posttoken: ', token);
var headers = new Headers();
headers.append('Content-Type', 'application/x-www-form-urlencoded');
this.http.post('http://localhost:8080/api/charge', token, {
headers: headers
}).subscribe(
data => console.log('data: ', data),
err => this.logError(err),
() => console.log('Authentication Complete')
);
}
logError(err) {
console.error('There was an error: ' + err);
}
}
난 다시 다음과 같은 응답 얻을 형태로 제출 :
from the posttoken: Object {id: "tok_19ASCZAgR5ZaHhRaLhfk7vcB", object: "token", card: Object, client_ip: "90.210.15.78", created: 1477868095…}
질문
왜 줄무늬가 제공하는 신용 카드를 추가되지 않습니다 새로 생성 한 정보 고객?
고객 ID (https://stripe.com/docs/api/node#create_charge-source)를 전달했거나 선택 사항 인 경우 청구 할 소스는 무엇입니까? – Searching