Skip to content

Commit

Permalink
fix: amount now is converted to cents
Browse files Browse the repository at this point in the history
  • Loading branch information
GiovannaK committed Mar 6, 2022
1 parent 3b39597 commit 38e333a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 18 deletions.
1 change: 0 additions & 1 deletion src/order/order.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import { TicketService } from 'src/ticket/ticket.service';
import { UpdateOrderDto } from './dto/update-order.dto';
import { StripeService } from 'src/stripe/stripe.service';
import { Ticket } from 'src/ticket/entities/ticket.entity';
import { Console } from 'console';

@Injectable()
export class OrderService {
Expand Down
40 changes: 23 additions & 17 deletions src/stripe/stripe.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,22 +107,28 @@ export class StripeService {
sellerId: any,
orderId: any,
) {
console.log('chegouuuududu');
console.log(amount, paymentMethodId, customerId, sellerId, orderId);
const payment = await this.stripe.paymentIntents.create({
amount,
customer: customerId,
payment_method: paymentMethodId,
currency: 'BRL',
confirm: true,
metadata: {
orderId: orderId,
},
transfer_data: {
destination: sellerId,
},
});
console.log('PAYYY', payment);
return payment;
const convertedAmount = this.convertToCents(amount);
try {
const payment = await this.stripe.paymentIntents.create({
amount: convertedAmount,
customer: customerId,
payment_method: paymentMethodId,
confirm: true,
currency: 'BRL',
metadata: {
orderId: orderId,
},
transfer_data: {
destination: sellerId,
},
});
return payment;
} catch (error) {
throw new InternalServerErrorException('Cannot process payment intent');
}
}

convertToCents(amount: number) {
return amount * 100;
}
}

0 comments on commit 38e333a

Please sign in to comment.